tcpsocketserver-help.pd 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. #N canvas 361 252 878 523 10;
  2. #X declare -stdpath extra/mrpeach;
  3. #X declare -stdpath extra/mrpeach;
  4. #X declare -lib moocow;
  5. #X declare -stdpath extra/mrpeach;
  6. #X declare -lib moocow;
  7. #X msg 471 74 print;
  8. #X text 521 75 list of connections;
  9. #X text 627 103 send to all clients;
  10. #X text 629 132 send to client 1;
  11. #X text 615 155 send to client on socket 504;
  12. #X text 613 28 'send' prefix is optional;
  13. #X text 474 48 (the first number is socket number);
  14. #X msg 556 257 disconnectsocket \$1;
  15. #X msg 484 284 disconnectclient \$1;
  16. #X floatatom 506 215 5 0 0 0 - - -;
  17. #X obj 484 235 f;
  18. #X obj 484 216 bng 15 250 50 0 empty empty empty 17 7 0 10 -258699
  19. -241291 -1;
  20. #X floatatom 578 216 5 0 0 0 - - -;
  21. #X obj 556 235 f;
  22. #X obj 556 216 bng 15 250 50 0 empty empty empty 17 7 0 10 -258699
  23. -241291 -1;
  24. #X text 483 197 disconnect by socket or client number;
  25. #X obj 618 335 unpack 0 0 0 0;
  26. #X floatatom 618 355 3 0 0 0 - - -;
  27. #X floatatom 649 355 3 0 0 0 - - -;
  28. #X floatatom 681 356 3 0 0 0 - - -;
  29. #X floatatom 715 356 3 0 0 0 - - -;
  30. #X text 616 372 IP;
  31. #X floatatom 569 355 5 0 0 0 - - -;
  32. #X text 566 371 socket;
  33. #X floatatom 520 376 5 0 0 0 - - -;
  34. #X text 520 391 number of connections;
  35. #X obj 471 433 spigot;
  36. #X obj 510 413 tgl 15 0 empty empty enable_print 17 7 0 10 -24198 -258699
  37. -258699 0 1;
  38. #X text 15 37 [tcpsocketserver <protocol> <port>];
  39. #X obj 469 311 cnv 15 185 22 empty empty empty 20 12 0 14 -204786 -66577
  40. 0;
  41. #X obj 471 314 tcpsocketserver FUDI 2468;
  42. #X text 15 115 [tcpsocketserver] is able to handle multiple sockets
  43. of a packet oriented protocol correctly \, unlike [tcpserver] \, which
  44. might mix up packets from different sockets.;
  45. #X text 24 308 - OSC;
  46. #X text 16 245 each protocol requires its own specific socket handler
  47. abstraction \, which should be named [tcpsocket.PROTOCOL]. currently
  48. available are the protocols:;
  49. #X text 23 293 - FUDI;
  50. #N canvas 702 157 472 356 EXTENDABILITY 0;
  51. #X text 3 39 Support for more protocols can easily be added. In order
  52. to do so:;
  53. #X text 5 10 EXTENDABILITY;
  54. #X text 6 105 - open tcpsocket.NEWPROTOCOL.pd;
  55. #X text 7 127 - edit the green-marked subpatch;
  56. #X text 10 208 - save it;
  57. #X text 12 227 - in order to use it \, instantiate:;
  58. #X text 46 247 [tcpsocketserver NEWPROTOCOL <port>];
  59. #X text 8 148 - replace code with code \, that creates proper packets
  60. out of the incoming stream for the desired protocol. don't forget to
  61. implement a reset mechanism \, in case a socket is closed in the middle
  62. of packet transmission.;
  63. #X text 5 83 - copy tcpsocket.FUDI.pd to tcpsocket.NEWPROTOCOL.pd;
  64. #X restore 21 387 pd EXTENDABILITY;
  65. #X text 17 453 Author: Roman Haefeli;
  66. #X text 16 468 Version: 2009-01-11;
  67. #X text 15 65 [tcpsocketserver] is meant to be a protocol-aware drop-in
  68. replacement for [tcpserver]. it uses same the same inlet and outlet
  69. configuration as [tcpserver].;
  70. #X text 469 478 only well-formed FUDI messages are received here.;
  71. #N canvas 463 454 147 274 EXAMPLES 0;
  72. #N canvas 705 77 571 769 FUDI 0;
  73. #X obj 8 52 cnv 15 550 240 empty empty client_1 20 12 0 14 -249661
  74. -66577 0;
  75. #X obj 24 206 tcpclient;
  76. #X msg 368 107 connect localhost 11001;
  77. #X msg 392 128 disconnect;
  78. #X obj 368 85 sel 1 0;
  79. #X obj 368 64 tgl 15 0 empty empty empty 17 7 0 10 -261234 -1 -1 0
  80. 1;
  81. #X obj 24 272 print CLIENT_1;
  82. #X msg 24 83 one two;
  83. #X obj 24 104 any2string 0 -1;
  84. #X msg 68 164 59 10;
  85. #X msg 32 130 32 116 104 114 101 101 23;
  86. #X obj 8 299 cnv 15 550 150 empty empty client_2 20 12 0 14 -249661
  87. -66577 0;
  88. #X msg 368 354 connect localhost 11001;
  89. #X msg 392 375 disconnect;
  90. #X obj 368 332 sel 1 0;
  91. #X obj 368 311 tgl 15 0 empty empty empty 17 7 0 10 -261234 -1 -1 0
  92. 1;
  93. #X obj 24 227 string2any 0 59;
  94. #X obj 24 247 route bang;
  95. #X obj 24 386 netclient;
  96. #X obj 24 415 print CLIENT_2;
  97. #X text 168 337 <- send FUDI message;
  98. #X obj 9 457 cnv 15 550 300 empty empty FUDI_server 20 12 0 14 -241408
  99. -66577 0;
  100. #X obj 11 613 tcpsocketserver FUDI 11001;
  101. #X obj 11 687 string2any 0 59;
  102. #X obj 11 708 route bang;
  103. #X obj 190 633 unpack 0 0 0 0;
  104. #X floatatom 190 653 3 0 0 0 - - -;
  105. #X floatatom 221 653 3 0 0 0 - - -;
  106. #X floatatom 253 654 3 0 0 0 - - -;
  107. #X floatatom 287 654 3 0 0 0 - - -;
  108. #X text 188 670 IP;
  109. #X floatatom 130 653 5 0 0 0 - - -;
  110. #X floatatom 70 654 5 0 0 0 - - -;
  111. #X text 59 669 clients;
  112. #X text 126 669 socket;
  113. #X text 131 688 <--;
  114. #X text 164 688 [tcpsocketserver FUDI] does _not_ remove the trailing
  115. ' \; ';
  116. #X text 164 83 1) start a FUDI message;
  117. #X text 231 131 2) continue;
  118. #X text 117 165 3) finish FUDI message (with semicolon - newline);
  119. #X text 390 65 connect;
  120. #X text 389 309 connect;
  121. #X text 19 488 [tcpsocketserver FUDI] doesn't take care of building
  122. FUDI-compliant messages. this should be done by the user.;
  123. #X text 153 229 4) try sending a message from client_2 during composing
  124. a message with client_1 and see \, how the server behaves.;
  125. #X text 278 535 <- this doesn't work;
  126. #X text 314 562 <- this should;
  127. #X msg 24 336 send four five six;
  128. #X msg 42 563 client 2 115 101 118 101 110 32 59 10;
  129. #X msg 41 534 client 2 115 101 118 101 110 32;
  130. #X obj 11 733 print SERVER;
  131. #X obj 20 32 import moocow;
  132. #X connect 1 0 16 0;
  133. #X connect 2 0 1 0;
  134. #X connect 3 0 1 0;
  135. #X connect 4 0 2 0;
  136. #X connect 4 1 3 0;
  137. #X connect 5 0 4 0;
  138. #X connect 7 0 8 0;
  139. #X connect 8 0 1 0;
  140. #X connect 9 0 1 0;
  141. #X connect 10 0 1 0;
  142. #X connect 12 0 18 0;
  143. #X connect 13 0 18 0;
  144. #X connect 14 0 12 0;
  145. #X connect 14 1 13 0;
  146. #X connect 15 0 14 0;
  147. #X connect 16 0 17 0;
  148. #X connect 17 1 6 0;
  149. #X connect 18 0 19 0;
  150. #X connect 22 0 23 0;
  151. #X connect 22 1 32 0;
  152. #X connect 22 2 31 0;
  153. #X connect 22 3 25 0;
  154. #X connect 23 0 24 0;
  155. #X connect 24 1 49 0;
  156. #X connect 25 0 26 0;
  157. #X connect 25 1 27 0;
  158. #X connect 25 2 28 0;
  159. #X connect 25 3 29 0;
  160. #X connect 46 0 18 0;
  161. #X connect 47 0 22 0;
  162. #X connect 48 0 22 0;
  163. #X restore 23 25 pd FUDI;
  164. #N canvas 697 77 579 756 OSC 0;
  165. #X obj 9 39 cnv 15 550 240 empty empty client_1 20 12 0 14 -249661
  166. -66577 0;
  167. #X obj 25 211 tcpclient;
  168. #X msg 357 229 disconnect;
  169. #X obj 333 186 sel 1 0;
  170. #X obj 333 165 tgl 15 0 empty empty empty 17 7 0 10 -261234 -1 -1 0
  171. 1;
  172. #X obj 25 259 print CLIENT_1;
  173. #X obj 9 286 cnv 15 550 150 empty empty client_2 20 12 0 14 -249661
  174. -66577 0;
  175. #X msg 393 362 disconnect;
  176. #X obj 369 319 sel 1 0;
  177. #X obj 369 298 tgl 15 0 empty empty empty 17 7 0 10 -261234 -1 -1 0
  178. 1;
  179. #X obj 25 417 print CLIENT_2;
  180. #X obj 10 444 cnv 15 550 300 empty empty OSC_server 20 12 0 14 -241408
  181. -66577 0;
  182. #X obj 188 636 unpack 0 0 0 0;
  183. #X floatatom 188 656 3 0 0 0 - - -;
  184. #X floatatom 219 656 3 0 0 0 - - -;
  185. #X floatatom 251 657 3 0 0 0 - - -;
  186. #X floatatom 285 657 3 0 0 0 - - -;
  187. #X text 186 673 IP;
  188. #X floatatom 130 656 5 0 0 0 - - -;
  189. #X floatatom 73 657 5 0 0 0 - - -;
  190. #X text 62 672 clients;
  191. #X text 126 672 socket;
  192. #X text 355 166 connect;
  193. #X text 390 296 connect;
  194. #X obj 16 616 tcpsocketserver OSC 11002;
  195. #X obj 16 694 unpackOSC;
  196. #X obj 16 720 print SERVER;
  197. #X msg 333 208 connect localhost 11002;
  198. #X msg 369 341 connect localhost 11002;
  199. #X obj 25 234 unpackOSCstream;
  200. #X obj 25 373 tcpclient;
  201. #X obj 25 395 unpackOSCstream;
  202. #X msg 49 498 /synth1/tone3/freq 440;
  203. #X msg 25 79 0 0 0 16 47 102 114 101 113;
  204. #X msg 41 104 0 0 0 44 105 0 0 0 0 1 184;
  205. #X text 155 324 send OSC message;
  206. #X msg 25 323 /amplitude 0.78;
  207. #X obj 25 347 packOSCstream;
  208. #X obj 16 522 packOSCstream;
  209. #X obj 16 594 list trim;
  210. #X msg 16 473 /synth3/tone4/amplitude 0.36;
  211. #X obj 180 555 hradio 15 1 0 2 empty empty empty 0 -8 0 10 -4034 -1
  212. -1 0;
  213. #X obj 180 573 + 1;
  214. #X text 221 555 client;
  215. #X obj 16 551 list prepend 1;
  216. #X obj 16 573 list prepend client;
  217. #X text 236 80 1) start sending an OSC packet;
  218. #X text 247 106 2) complete the OSC packet;
  219. #X text 59 137 also try sending an OSC packet from client_2 between
  220. 1) and 2);
  221. #X text 124 520 <- use [packOSCstream] in order to create OSC packets
  222. suitable for tcp transport.;
  223. #X text 238 486 send to clients;
  224. #X text 93 695 <---;
  225. #X text 139 694 CAUTION: not [unpackOSCstream] is used here \, since
  226. [tcpsocket.OSC] already unwraps the OSC message;
  227. #X obj 8 9 import moocow;
  228. #X connect 1 0 29 0;
  229. #X connect 2 0 1 0;
  230. #X connect 3 0 27 0;
  231. #X connect 3 1 2 0;
  232. #X connect 4 0 3 0;
  233. #X connect 7 0 30 0;
  234. #X connect 8 0 28 0;
  235. #X connect 8 1 7 0;
  236. #X connect 9 0 8 0;
  237. #X connect 12 0 13 0;
  238. #X connect 12 1 14 0;
  239. #X connect 12 2 15 0;
  240. #X connect 12 3 16 0;
  241. #X connect 24 0 25 0;
  242. #X connect 24 1 19 0;
  243. #X connect 24 2 18 0;
  244. #X connect 24 3 12 0;
  245. #X connect 25 0 26 0;
  246. #X connect 27 0 1 0;
  247. #X connect 28 0 30 0;
  248. #X connect 29 0 5 0;
  249. #X connect 30 0 31 0;
  250. #X connect 31 0 10 0;
  251. #X connect 32 0 38 0;
  252. #X connect 33 0 1 0;
  253. #X connect 34 0 1 0;
  254. #X connect 36 0 37 0;
  255. #X connect 37 0 30 0;
  256. #X connect 38 0 44 0;
  257. #X connect 39 0 24 0;
  258. #X connect 40 0 38 0;
  259. #X connect 41 0 42 0;
  260. #X connect 42 0 44 1;
  261. #X connect 44 0 45 0;
  262. #X connect 45 0 39 0;
  263. #X restore 23 49 pd OSC;
  264. #X restore 21 365 pd EXAMPLES;
  265. #X obj 471 455 print FUDI;
  266. #X msg 471 101 broadcast 97 98 99 59 10;
  267. #X msg 471 128 client 1 97 98 99 59 10;
  268. #X msg 471 155 send 504 97 98 99 59 10;
  269. #X msg 471 28 10 97 98 99 59 10;
  270. #X text 17 8 TCPSOCKETSERVER - a protocol-aware wrapper aroun [tcpserver]
  271. ;
  272. #X text 13 167 [tcpsocketserver] dynamically creates (internally) an
  273. instance of a socket handler abstraction [tcpsocket.PROTOCOL] for each
  274. opened socket. every socket handler creates proper packets from the
  275. incoming stream and sends them to the left outlet of [tcpsocketserver].
  276. ;
  277. #X connect 0 0 30 0;
  278. #X connect 7 0 30 0;
  279. #X connect 8 0 30 0;
  280. #X connect 9 0 10 1;
  281. #X connect 10 0 8 0;
  282. #X connect 11 0 10 0;
  283. #X connect 12 0 13 1;
  284. #X connect 13 0 7 0;
  285. #X connect 14 0 13 0;
  286. #X connect 16 0 17 0;
  287. #X connect 16 1 18 0;
  288. #X connect 16 2 19 0;
  289. #X connect 16 3 20 0;
  290. #X connect 26 0 41 0;
  291. #X connect 27 0 26 1;
  292. #X connect 30 0 26 0;
  293. #X connect 30 1 24 0;
  294. #X connect 30 2 22 0;
  295. #X connect 30 3 16 0;
  296. #X connect 42 0 30 0;
  297. #X connect 43 0 30 0;
  298. #X connect 44 0 30 0;
  299. #X connect 45 0 30 0;