diff options
author | Martin Peach <mrpeach@users.sourceforge.net> | 2009-03-09 16:01:10 +0000 |
---|---|---|
committer | Martin Peach <mrpeach@users.sourceforge.net> | 2009-03-09 16:01:10 +0000 |
commit | f220eb32d9cd98a9a3d53409c1432909fb506106 (patch) | |
tree | 3d5c0f99ede96a72dc2d61fb29c367a9d1cba828 | |
parent | ed3f143edde18f4fc3781293c50e25ca843320db (diff) |
The 'sent' message now contains client number, bytes sent, socket number. Empty 'send' message triggers list of client messages on right outlet. Empty socket number message causes a client message on right outlet.
Help patch updated.
svn path=/trunk/externals/mrpeach/; revision=10852
-rw-r--r-- | net/tcpserver-help.pd | 75 | ||||
-rw-r--r-- | net/tcpserver.c | 27 |
2 files changed, 62 insertions, 40 deletions
diff --git a/net/tcpserver-help.pd b/net/tcpserver-help.pd index 0a12bd5..e56209d 100644 --- a/net/tcpserver-help.pd +++ b/net/tcpserver-help.pd @@ -1,4 +1,4 @@ -#N canvas 278 60 1204 806 12;
+#N canvas 220 28 1204 762 12;
#X msg 143 -36 print;
#X floatatom 448 290 5 0 0 0 - - -;
#X floatatom 472 340 5 0 0 0 - - -;
@@ -53,7 +53,7 @@ #X msg 63 -116 disconnectsocket \$1;
#X msg 20 -159 disconnectclient \$1;
#X obj 714 238 s toserver;
-#X obj 242 163 r toserver;
+#X obj 425 238 r toserver;
#X floatatom 247 -198 5 0 0 0 - - -;
#X obj 225 -179 f;
#X obj 225 -198 bng 15 250 50 0 empty empty empty 17 7 0 10 -258699
@@ -69,7 +69,7 @@ hang pd!;
#X obj 425 393 spigot;
#X obj 464 373 tgl 15 0 empty empty enable_print 17 7 0 10 -24198 -258699
--45076 0 1;
+-45076 1 1;
#X msg 263 84 dump \$1;
#X obj 87 69 tgl 15 0 empty empty enable_dump 17 7 0 10 -4034 -257985
-1 1 1;
@@ -85,31 +85,37 @@ hang pd!; ;
#X text -33 -228 send a file to client 1;
#X msg 287 108 client 1 72 101 108 108 111 13 10;
-#X floatatom 688 338 9 0 0 0 - - -;
-#X obj 737 313 print status;
-#X obj 621 313 unpack 0 0;
-#X floatatom 649 361 5 0 0 0 - - -;
-#X text 579 361 to_client;
+#X floatatom 682 351 9 0 0 0 - - -;
+#X obj 758 313 print status;
+#X floatatom 642 374 5 0 0 0 - - -;
+#X text 572 373 to_client;
#X msg 215 36 client;
#X msg 192 13 client 1;
#X text 260 12 get state of client 1;
#X text 353 60 send (binary) 1 2 3 to client 1;
-#X obj 621 286 route sent client;
-#X floatatom 796 443 5 0 0 0 - - -;
-#X symbolatom 828 416 20 0 0 0 - - -;
-#X floatatom 765 416 5 0 0 0 - - -;
-#X text 755 340 bytes;
-#X text 648 338 sent;
+#X obj 642 286 route sent client;
+#X floatatom 817 443 5 0 0 0 - - -;
+#X symbolatom 849 416 20 0 0 0 - - -;
+#X floatatom 786 416 5 0 0 0 - - -;
+#X text 749 350 bytes;
+#X text 642 350 sent;
#X msg 313 134 clientbuf 1 65536;
-#X text 35 450 2009/03/01 Martin Peach;
-#X obj 765 392 unpack 0 0 s 0;
-#X floatatom 860 464 7 0 0 0 - - -;
-#X text 705 464 length of send buffer:;
-#X text 745 442 socket:;
-#X text 714 415 client:;
-#X text 805 415 ip:;
+#X obj 786 392 unpack 0 0 s 0;
+#X floatatom 881 464 7 0 0 0 - - -;
+#X text 726 464 length of send buffer:;
+#X text 766 442 socket:;
+#X text 735 415 client:;
+#X text 826 415 ip:;
#X text 443 133 set send-buffer size for client 1;
#X text 267 36 get state of all clients (list on right outlet);
+#X obj 642 325 unpack 0 0 0;
+#X floatatom 723 392 5 0 0 0 - - -;
+#X text 653 391 on_socket;
+#X text 35 450 2009/03/09 Martin Peach;
+#X msg 344 165 send;
+#X msg 369 190 1156;
+#X text 387 164 output 'client' message for all sockets;
+#X text 409 190 output 'client' message for socket 1156;
#X connect 0 0 60 0;
#X connect 3 0 4 0;
#X connect 3 1 5 0;
@@ -152,18 +158,21 @@ hang pd!; #X connect 60 1 1 0;
#X connect 60 2 2 0;
#X connect 60 3 3 0;
-#X connect 60 4 75 0;
+#X connect 60 4 74 0;
#X connect 61 0 60 0;
#X connect 65 0 60 0;
-#X connect 68 0 69 0;
-#X connect 68 1 66 0;
+#X connect 70 0 60 0;
#X connect 71 0 60 0;
-#X connect 72 0 60 0;
-#X connect 75 0 68 0;
-#X connect 75 1 83 0;
-#X connect 75 2 67 0;
-#X connect 81 0 60 0;
-#X connect 83 0 78 0;
-#X connect 83 1 76 0;
-#X connect 83 2 77 0;
-#X connect 83 3 84 0;
+#X connect 74 0 89 0;
+#X connect 74 1 81 0;
+#X connect 74 2 67 0;
+#X connect 80 0 60 0;
+#X connect 81 0 77 0;
+#X connect 81 1 75 0;
+#X connect 81 2 76 0;
+#X connect 81 3 82 0;
+#X connect 89 0 68 0;
+#X connect 89 1 66 0;
+#X connect 89 2 90 0;
+#X connect 93 0 60 0;
+#X connect 94 0 60 0;
diff --git a/net/tcpserver.c b/net/tcpserver.c index ac31f25..9090c66 100644 --- a/net/tcpserver.c +++ b/net/tcpserver.c @@ -106,6 +106,7 @@ static void tcpserver_send(t_tcpserver *x, t_symbol *s, int argc, t_atom *argv); static void tcpserver_send_bytes(int sockfd, t_tcpserver *x, int argc, t_atom *argv); static size_t tcpserver_send_buf(int client, int sockfd, char *byte_buf, size_t length); static void tcpserver_client_send(t_tcpserver *x, t_symbol *s, int argc, t_atom *argv); +static void tcpserver_output_client_state(t_tcpserver *x, int client); static int tcpserver_get_socket_send_buf_size(int sockfd); static int tcpserver_set_socket_send_buf_size(int sockfd, int size); static void tcpserver_buf_size(t_tcpserver *x, t_symbol *s, int argc, t_atom *argv); @@ -296,7 +297,7 @@ static void tcpserver_send_bytes(int client, t_tcpserver *x, int argc, t_atom *a int sockfd = x->x_fd[client]; char fpath[FILENAME_MAX]; FILE *fptr; - t_atom output_atom[2]; + t_atom output_atom[3]; /* process & send data */ if(sockfd >= 0) @@ -376,7 +377,8 @@ static void tcpserver_send_bytes(int client, t_tcpserver *x, int argc, t_atom *a else post("%s: not a valid socket number (%d)", objName, sockfd); SETFLOAT(&output_atom[0], client+1); SETFLOAT(&output_atom[1], flen); - outlet_anything( x->x_status_outlet, gensym("sent"), 2, output_atom); + SETFLOAT(&output_atom[2], sockfd); + outlet_anything( x->x_status_outlet, gensym("sent"), 3, output_atom); } static size_t tcpserver_send_buf(int client, int sockfd, char *byte_buf, size_t length) @@ -431,20 +433,20 @@ static void tcpserver_send(t_tcpserver *x, t_symbol *s, int argc, t_atom *argv) post("%s_send: no clients connected", objName); return; } - if(argc < 2) + if(argc == 0) /* no socket specified: output state of all sockets */ { - post("%s_send: nothing to send", objName); + tcpserver_output_client_state(x, client); return; } /* get socket number of connection (first element in list) */ if(argv[0].a_type == A_FLOAT) { sockfd = atom_getfloatarg(0, argc, argv); - for(i = 0; i < x->x_nconnections; i++) /* check if connection exists */ + for(i = 0; i < x->x_nconnections; i++) /* check if connection exists */ { if(x->x_fd[i] == sockfd) { - client = i; /* the client we're sending to */ + client = i; /* the client we're sending to */ break; } } @@ -459,6 +461,11 @@ static void tcpserver_send(t_tcpserver *x, t_symbol *s, int argc, t_atom *argv) post("%s_send: no socket specified", objName); return; } + if (argc < 2) /* nothing to send: output state of this socket */ + { + tcpserver_output_client_state(x, client+1); + return; + } tcpserver_send_bytes(client, x, argc-1, &argv[1]); } @@ -529,7 +536,6 @@ static void tcpserver_client_disconnect(t_tcpserver *x, t_floatarg fclient) static void tcpserver_client_send(t_tcpserver *x, t_symbol *s, int argc, t_atom *argv) { int client = -1; - t_atom output_atom[4]; if(x->x_nconnections <= 0) { @@ -558,6 +564,13 @@ static void tcpserver_client_send(t_tcpserver *x, t_symbol *s, int argc, t_atom tcpserver_send_bytes(client, x, argc-1, &argv[1]); return; } + tcpserver_output_client_state(x, client); +} + +static void tcpserver_output_client_state(t_tcpserver *x, int client) +{ + t_atom output_atom[4]; + if (client == -1) { /* output parameters of all connections via status outlet */ |