From fa47f6ea2ee29607de4d97a79d24b83f0b8c25f9 Mon Sep 17 00:00:00 2001 From: Roman Haefeli Date: Tue, 1 Feb 2011 21:52:52 +0000 Subject: those abstractions actually belong to the 'net' section svn path=/trunk/externals/mrpeach/; revision=14850 --- net/tcpsocketserver-help.pd | 301 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 301 insertions(+) create mode 100644 net/tcpsocketserver-help.pd (limited to 'net/tcpsocketserver-help.pd') diff --git a/net/tcpsocketserver-help.pd b/net/tcpsocketserver-help.pd new file mode 100644 index 0000000..d0e6045 --- /dev/null +++ b/net/tcpsocketserver-help.pd @@ -0,0 +1,301 @@ +#N canvas 35 3 878 523 10; +#X declare -stdpath extra/mrpeach; +#X declare -stdlib extra/pdstring declare -stdlib extra/maxlib; +#X declare -stdpath extra/mrpeach; +#X declare -stdlib extra/pdstring declare -stdlib extra/maxlib; +#X declare -stdpath extra/mrpeach; +#X msg 471 74 print; +#X text 521 75 list of connections; +#X text 627 103 send to all clients; +#X text 629 132 send to client 1; +#X text 615 155 send to client on socket 504; +#X text 613 28 'send' prefix is optional; +#X text 474 48 (the first number is socket number); +#X msg 556 257 disconnectsocket \$1; +#X msg 484 284 disconnectclient \$1; +#X floatatom 506 215 5 0 0 0 - - -; +#X obj 484 235 f; +#X obj 484 216 bng 15 250 50 0 empty empty empty 17 7 0 10 -258699 +-241291 -1; +#X floatatom 578 216 5 0 0 0 - - -; +#X obj 556 235 f; +#X obj 556 216 bng 15 250 50 0 empty empty empty 17 7 0 10 -258699 +-241291 -1; +#X text 483 197 disconnect by socket or client number; +#X obj 618 335 unpack 0 0 0 0; +#X floatatom 618 355 3 0 0 0 - - -; +#X floatatom 649 355 3 0 0 0 - - -; +#X floatatom 681 356 3 0 0 0 - - -; +#X floatatom 715 356 3 0 0 0 - - -; +#X text 616 372 IP; +#X floatatom 569 355 5 0 0 0 - - -; +#X text 566 371 socket; +#X floatatom 520 376 5 0 0 0 - - -; +#X text 520 391 number of connections; +#X obj 471 433 spigot; +#X obj 510 413 tgl 15 0 empty empty enable_print 17 7 0 10 -24198 -258699 +-258699 0 1; +#X text 15 37 [tcpsocketserver ]; +#X obj 469 311 cnv 15 185 22 empty empty empty 20 12 0 14 -204786 -66577 +0; +#X obj 471 314 tcpsocketserver FUDI 2468; +#X text 15 115 [tcpsocketserver] is able to handle multiple sockets +of a packet oriented protocol correctly \, unlike [tcpserver] \, which +might mix up packets from different sockets.; +#X text 24 308 - OSC; +#X text 16 245 each protocol requires its own specific socket handler +abstraction \, which should be named [tcpsocket.PROTOCOL]. currently +available are the protocols:; +#X text 23 293 - FUDI; +#N canvas 704 167 472 356 EXTENDABILITY 0; +#X text 3 39 Support for more protocols can easily be added. In order +to do so:; +#X text 5 10 EXTENDABILITY; +#X text 6 105 - open tcpsocket.NEWPROTOCOL.pd; +#X text 7 127 - edit the green-marked subpatch; +#X text 10 208 - save it; +#X text 12 227 - in order to use it \, instantiate:; +#X text 46 247 [tcpsocketserver NEWPROTOCOL ]; +#X text 8 148 - replace code with code \, that creates proper packets +out of the incoming stream for the desired protocol. don't forget to +implement a reset mechanism \, in case a socket is closed in the middle +of packet transmission.; +#X text 5 83 - copy tcpsocket.FUDI.pd to tcpsocket.NEWPROTOCOL.pd; +#X restore 21 387 pd EXTENDABILITY; +#X text 17 453 Author: Roman Haefeli; +#X text 16 468 Version: 2009-01-11; +#X text 15 65 [tcpsocketserver] is meant to be a protocol-aware drop-in +replacement for [tcpserver]. it uses same the same inlet and outlet +configuration as [tcpserver].; +#X text 469 478 only well-formed FUDI messages are received here.; +#N canvas 469 232 147 274 EXAMPLES 0; +#N canvas 231 0 579 756 FUDI 0; +#X obj 9 39 cnv 15 550 240 empty empty client_1 20 12 0 14 -249661 +-66577 0; +#X obj 25 193 tcpclient; +#X msg 369 94 connect localhost 11001; +#X msg 393 115 disconnect; +#X obj 369 72 sel 1 0; +#X obj 369 51 tgl 15 0 empty empty empty 17 7 0 10 -261234 -1 -1 0 +1; +#X obj 25 259 print CLIENT_1; +#X msg 25 70 one two; +#X obj 25 91 any2string 0 -1; +#X msg 69 151 59 10; +#X msg 33 117 32 116 104 114 101 101 23; +#X obj 9 286 cnv 15 550 150 empty empty client_2 20 12 0 14 -249661 +-66577 0; +#X msg 369 341 connect localhost 11001; +#X msg 393 362 disconnect; +#X obj 369 319 sel 1 0; +#X obj 369 298 tgl 15 0 empty empty empty 17 7 0 10 -261234 -1 -1 0 +1; +#X obj 25 214 string2any 0 59; +#X obj 25 234 route bang; +#X obj 25 373 netclient; +#X obj 8 9 declare -stdlib extra/pdstring declare -stdlib extra/maxlib +; +#X obj 25 402 print CLIENT_2; +#X text 169 324 <- send FUDI message; +#X obj 10 444 cnv 15 550 300 empty empty FUDI_server 20 12 0 14 -241408 +-66577 0; +#X obj 12 600 tcpsocketserver FUDI 11001; +#X obj 12 674 string2any 0 59; +#X obj 12 695 route bang; +#X obj 191 620 unpack 0 0 0 0; +#X floatatom 191 640 3 0 0 0 - - -; +#X floatatom 222 640 3 0 0 0 - - -; +#X floatatom 254 641 3 0 0 0 - - -; +#X floatatom 288 641 3 0 0 0 - - -; +#X text 189 657 IP; +#X floatatom 131 640 5 0 0 0 - - -; +#X floatatom 71 641 5 0 0 0 - - -; +#X text 60 656 clients; +#X text 127 656 socket; +#X text 132 675 <--; +#X text 165 675 [tcpsocketserver FUDI] does _not_ remove the trailing +' \; '; +#X text 165 70 1) start a FUDI message; +#X text 232 118 2) continue; +#X text 118 152 3) finish FUDI message (with semicolon - newline); +#X text 391 52 connect; +#X text 390 296 connect; +#X text 20 475 [tcpsocketserver FUDI] doesn't take care of building +FUDI-compliant messages. this should be done by the user.; +#X text 154 216 4) try sending a message from client_2 during composing +a message with client_1 and see \, how the server behaves.; +#X text 279 522 <- this doesn't work; +#X text 315 549 <- this should; +#X msg 25 323 send four five six; +#X msg 43 550 client 2 115 101 118 101 110 32 59 10; +#X msg 42 521 client 2 115 101 118 101 110 32; +#X obj 12 720 print SERVER; +#X connect 1 0 16 0; +#X connect 2 0 1 0; +#X connect 3 0 1 0; +#X connect 4 0 2 0; +#X connect 4 1 3 0; +#X connect 5 0 4 0; +#X connect 7 0 8 0; +#X connect 8 0 1 0; +#X connect 9 0 1 0; +#X connect 10 0 1 0; +#X connect 12 0 18 0; +#X connect 13 0 18 0; +#X connect 14 0 12 0; +#X connect 14 1 13 0; +#X connect 15 0 14 0; +#X connect 16 0 17 0; +#X connect 17 1 6 0; +#X connect 18 0 20 0; +#X connect 23 0 24 0; +#X connect 23 1 33 0; +#X connect 23 2 32 0; +#X connect 23 3 26 0; +#X connect 24 0 25 0; +#X connect 25 1 50 0; +#X connect 26 0 27 0; +#X connect 26 1 28 0; +#X connect 26 2 29 0; +#X connect 26 3 30 0; +#X connect 47 0 18 0; +#X connect 48 0 23 0; +#X connect 49 0 23 0; +#X restore 23 25 pd FUDI; +#N canvas 231 0 579 756 OSC 0; +#X obj 9 39 cnv 15 550 240 empty empty client_1 20 12 0 14 -249661 +-66577 0; +#X obj 25 211 tcpclient; +#X msg 357 229 disconnect; +#X obj 333 186 sel 1 0; +#X obj 333 165 tgl 15 0 empty empty empty 17 7 0 10 -261234 -1 -1 0 +1; +#X obj 25 259 print CLIENT_1; +#X obj 9 286 cnv 15 550 150 empty empty client_2 20 12 0 14 -249661 +-66577 0; +#X msg 393 362 disconnect; +#X obj 369 319 sel 1 0; +#X obj 369 298 tgl 15 0 empty empty empty 17 7 0 10 -261234 -1 -1 0 +1; +#X obj 8 9 declare -stdlib extra/pdstring declare -stdlib extra/maxlib +; +#X obj 25 417 print CLIENT_2; +#X obj 10 444 cnv 15 550 300 empty empty OSC_server 20 12 0 14 -241408 +-66577 0; +#X obj 188 636 unpack 0 0 0 0; +#X floatatom 188 656 3 0 0 0 - - -; +#X floatatom 219 656 3 0 0 0 - - -; +#X floatatom 251 657 3 0 0 0 - - -; +#X floatatom 285 657 3 0 0 0 - - -; +#X text 186 673 IP; +#X floatatom 130 656 5 0 0 0 - - -; +#X floatatom 73 657 5 0 0 0 - - -; +#X text 62 672 clients; +#X text 126 672 socket; +#X text 355 166 connect; +#X text 390 296 connect; +#X obj 16 616 tcpsocketserver OSC 11002; +#X obj 16 694 unpackOSC; +#X obj 16 720 print SERVER; +#X msg 333 208 connect localhost 11002; +#X msg 369 341 connect localhost 11002; +#X obj 25 234 unpackOSCstream; +#X obj 25 373 tcpclient; +#X obj 25 395 unpackOSCstream; +#X msg 49 498 /synth1/tone3/freq 440; +#X msg 25 79 0 0 0 16 47 102 114 101 113; +#X msg 41 104 0 0 0 44 105 0 0 0 0 1 184; +#X text 155 324 send OSC message; +#X msg 25 323 /amplitude 0.78; +#X obj 25 347 packOSCstream; +#X obj 16 522 packOSCstream; +#X obj 16 594 list trim; +#X msg 16 473 /synth3/tone4/amplitude 0.36; +#X obj 180 555 hradio 15 1 0 2 empty empty empty 0 -8 0 10 -4034 -1 +-1 0; +#X obj 180 573 + 1; +#X text 221 555 client; +#X obj 16 551 list prepend 1; +#X obj 16 573 list prepend client; +#X text 236 80 1) start sending an OSC packet; +#X text 247 106 2) complete the OSC packet; +#X text 59 137 also try sending an OSC packet from client_2 between +1) and 2); +#X text 124 520 <- use [packOSCstream] in order to create OSC packets +suitable for tcp transport.; +#X text 238 486 send to clients; +#X text 93 695 <---; +#X text 139 694 CAUTION: not [unpackOSCstream] is used here \, since +[tcpsocket.OSC] already removes the 4-byte header.; +#X connect 1 0 30 0; +#X connect 2 0 1 0; +#X connect 3 0 28 0; +#X connect 3 1 2 0; +#X connect 4 0 3 0; +#X connect 7 0 31 0; +#X connect 8 0 29 0; +#X connect 8 1 7 0; +#X connect 9 0 8 0; +#X connect 13 0 14 0; +#X connect 13 1 15 0; +#X connect 13 2 16 0; +#X connect 13 3 17 0; +#X connect 25 0 26 0; +#X connect 25 1 20 0; +#X connect 25 2 19 0; +#X connect 25 3 13 0; +#X connect 26 0 27 0; +#X connect 28 0 1 0; +#X connect 29 0 31 0; +#X connect 30 0 5 0; +#X connect 31 0 32 0; +#X connect 32 0 11 0; +#X connect 33 0 39 0; +#X connect 34 0 1 0; +#X connect 35 0 1 0; +#X connect 37 0 38 0; +#X connect 38 0 31 0; +#X connect 39 0 45 0; +#X connect 40 0 25 0; +#X connect 41 0 39 0; +#X connect 42 0 43 0; +#X connect 43 0 45 1; +#X connect 45 0 46 0; +#X connect 46 0 40 0; +#X restore 23 49 pd OSC; +#X restore 21 365 pd EXAMPLES; +#X obj 471 455 print FUDI; +#X msg 471 101 broadcast 97 98 99 59 10; +#X msg 471 128 client 1 97 98 99 59 10; +#X msg 471 155 send 504 97 98 99 59 10; +#X msg 471 28 10 97 98 99 59 10; +#X text 17 8 TCPSOCKETSERVER - a protocol-aware wrapper aroun [tcpserver] +; +#X text 13 167 [tcpsocketserver] dynamically creates (internally) an +instance of a socket handler abstraction [tcpsocket.PROTOCOL] for each +opened socket. every socket handler creates proper packets from the +incoming stream and sends them to the left outlet of [tcpsocketserver]. +; +#X connect 0 0 30 0; +#X connect 7 0 30 0; +#X connect 8 0 30 0; +#X connect 9 0 10 1; +#X connect 10 0 8 0; +#X connect 11 0 10 0; +#X connect 12 0 13 1; +#X connect 13 0 7 0; +#X connect 14 0 13 0; +#X connect 16 0 17 0; +#X connect 16 1 18 0; +#X connect 16 2 19 0; +#X connect 16 3 20 0; +#X connect 26 0 41 0; +#X connect 27 0 26 1; +#X connect 30 0 26 0; +#X connect 30 1 24 0; +#X connect 30 2 22 0; +#X connect 30 3 16 0; +#X connect 42 0 30 0; +#X connect 43 0 30 0; +#X connect 44 0 30 0; +#X connect 45 0 30 0; -- cgit v1.2.1