On Die, 2013-07-02 at 20:38 +0200, Antoine Villeret wrote:
> Hi roman, 
> 
> 
> the code around networking object are some workarounds for differents
> bugs, 
> the first was a crash when client number reach 32, but it seems to be
> fixed, I can't reproduce this anymore
> the second was something strange if several clients connect to the
> same server at the same time (when patch launch for example), so I add
> a timeout, if no answer in this timeout, the client disconnect
> there is also a mechanism to choose an available port at startup in
> server and the client try different port until it get a connection...

Ok, I think I understand a bit more now. 

The server tries a different port when the first port is not available
right? It scans until it finds one. I don't see what the client is
supposed to do. There is some code to scan through ports, but actually
when I tested your client, it always only tried 10000. 

I don't think that dynamic ports are a good solution.  If you find a
proper way to disconnect the clients, then you shouldn't experience the
problem of a busy port when restarting the server. This only happens
when you close the server patch without disconnecting the clients.
Anyway, the port scanning of the clients would be so slow that probably
by the time they found the correct port, the initial port would be free
again (depending on OS, though). 

Then I think your way of testing might expose bugs that you wouldn't
experience in real life. I mean that is good for bug reporting, but it
isn't really meaningful to connect many clients in the same instance of
Pd, even less so to connect them all in zero logical time. If you would
run your clients in different instances of Pd (what I think is your plan
anyway), you wouldn't have to find workarounds for issues exposed by
running clients in the same instance. 

I figured you can only properly disconnect all clients with
[net/tcpserver]. Unlike [iemnet/tcpserver], it has no 'disconnect'
method. So you have to disconnect each client separately.
[iemnet/tcpserver] is supposed to disconnect all clients with
'disconnect', but actually the [iemnet/tcpclient]s seem to ignore it and
keep their connected state (outlet 3 doesn't switch to 0). Finishing
sessions seems generally to be still a problem with iemnet. Also when a
client disconnects, the server often doesn't change the number of
connected clients. The net library seems much more robust in this
regard.

I simplified your patches a lot and as simple as they are, they seem to
work fine here. Note about the server: you need to disconnect all
clients before you close the server patch. This will the leave the
network socket in a clean state and you will be able to occupy that port
immediately again. The client tries to connect at a rate of one try per
second. In case it gets disconnected by the server, it waits 5 seconds
before trying to connect again. This gives you time to disconnect all
clients and shutdown the server properly. 



> all of this is quite complex for a not so difficult task : I want to
> make several instance of Pd talking to each other on one machine
> 
> 
> I started with udpsend/udpreceive but I found no way to do broadcast
> on localhost 

You mean broadcast on all ports? I don't think that something like that
exists.

> and I do need to have lots of clients
> multicasting is not a solution because it need to have a working
> networking interface

If you want to run many instances of Pd on localhost, then multicast
can't help you. It is about sending data to many clients on different
IPs at the same time. You want to send to many clients on localhost.

> then I tried udpserver which doesn't work (at least the version in the
> pd's SVN)
> then I switch to tcpserver and I got a lots of troubles...

Things look good as long as you think you only need streams. As soon as
you figure out that you need to send packets between your instances of
Pd, things get really complex wit [tcpserver].

> I will try out iohannes version of iemnet and I'll also investigate
> those bugs

As of today, both libraries net and iemnet have known bugs. My examples
use net because [iemnet/tcpserver] can't disconnect clients.

> but other (simpler) solutions are welcome :-)

See attachment. I tested them with Pd-extended 0.43.3 on Ubuntu 12.04

Roman

#N canvas 520 44 387 366 10;
#X msg 104 205 connect localhost 10000;
#X obj 108 284 s \$0.connection;
#X obj 104 24 r \$0.connection;
#X obj 104 51 == 0;
#X obj 104 176 metro 1000;
#X obj 58 25 inlet;
#X obj 58 329 outlet;
#X obj 257 34 loadbang;
#X msg 257 56 0;
#X obj 257 79 s \$0.connection;
#X obj 104 139 delay 5000;
#X obj 104 75 sel 1;
#X obj 131 96 t b a;
#X msg 131 118 stop;
#X obj 58 233 net/tcpclient;
#X connect 0 0 14 0;
#X connect 2 0 3 0;
#X connect 3 0 11 0;
#X connect 4 0 0 0;
#X connect 5 0 14 0;
#X connect 7 0 8 0;
#X connect 8 0 9 0;
#X connect 10 0 4 0;
#X connect 11 0 10 0;
#X connect 11 1 12 0;
#X connect 12 0 13 0;
#X connect 12 1 4 0;
#X connect 13 0 10 0;
#X connect 14 0 6 0;
#X connect 14 2 1 0;
#N canvas 959 63 450 300 10;
#X obj 35 262 s \$0.broadcast;
#X obj 35 22 r \$0.broadcast;
#X obj 35 48 list prepend broadcast;
#X obj 35 73 list trim;
#X obj 35 127 net/tcpserver 10000;
#X obj 62 180 s \$0.num_of_clients;
#X obj 279 43 r \$0.num_of_clients;
#X obj 264 66 f;
#X obj 264 20 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X text 284 19 disconnect all;
#X obj 264 88 t a b;
#X obj 264 110 until;
#X obj 264 132 f;
#X obj 264 154 + 1;
#X msg 306 112 0;
#X msg 264 177 disconnectclient \$1;
#X connect 1 0 2 0;
#X connect 2 0 3 0;
#X connect 3 0 4 0;
#X connect 4 0 0 0;
#X connect 4 1 5 0;
#X connect 6 0 7 1;
#X connect 7 0 10 0;
#X connect 8 0 7 0;
#X connect 10 0 11 0;
#X connect 10 1 14 0;
#X connect 11 0 12 0;
#X connect 12 0 13 0;
#X connect 13 0 12 1;
#X connect 13 0 15 0;
#X connect 14 0 12 1;
#X connect 15 0 4 0;
_______________________________________________
Pd-dev mailing list
Pd-dev@iem.at
http://lists.puredata.info/listinfo/pd-dev

Reply via email to