<div dir="ltr">2013/7/3 Roman Haefeli <span dir="ltr">&lt;<a href="mailto:reduzent@gmail.com" target="_blank">reduzent@gmail.com</a>&gt;</span><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div class="im">On Die, 2013-07-02 at 20:38 +0200, Antoine Villeret wrote:<br>
&gt; Hi roman,<br>
&gt;<br>
&gt;<br>
&gt; the code around networking object are some workarounds for differents<br>
&gt; bugs,<br>
&gt; the first was a crash when client number reach 32, but it seems to be<br>
&gt; fixed, I can&#39;t reproduce this anymore<br>
&gt; the second was something strange if several clients connect to the<br>
&gt; same server at the same time (when patch launch for example), so I add<br>
&gt; a timeout, if no answer in this timeout, the client disconnect<br>
&gt; there is also a mechanism to choose an available port at startup in<br>
&gt; server and the client try different port until it get a connection...<br>
<br>
</div>Ok, I think I understand a bit more now.<br>
<br>
The server tries a different port when the first port is not available<br>
right? It scans until it finds one. I don&#39;t see what the client is<br>
supposed to do. There is some code to scan through ports, but actually<br>
when I tested your client, it always only tried 10000. </blockquote><div><br></div><div style>the client try to connect to a port if there is a server on that port, it gets a connection</div><div style>if there is no server, it can&#39;t get connected and so the client tries another port.</div>

<div style>at least it&#39;s supposed to do so... </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
I don&#39;t think that dynamic ports are a good solution.  If you find a<br>
proper way to disconnect the clients, then you shouldn&#39;t experience the<br>
problem of a busy port when restarting the server. This only happens<br>
when you close the server patch without disconnecting the clients.<br>
Anyway, the port scanning of the clients would be so slow that probably<br>
by the time they found the correct port, the initial port would be free<br>
again (depending on OS, though).<br></blockquote><div> </div><div style>yep, I&#39;m aware that dynamic port finding is not the best solution but due to bugs related before, iemnet&#39;s [tcpserver] used to crash pd.</div>

<div style>And so port stay busy until a certain timeout (here 60 sec), finding a new available port restores the installation in a working state more quickly.</div><div style><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<br>
Then I think your way of testing might expose bugs that you wouldn&#39;t<br>
experience in real life. I mean that is good for bug reporting, but it<br>
isn&#39;t really meaningful to connect many clients in the same instance of<br>
Pd, even less so to connect them all in zero logical time. If you would<br>
run your clients in different instances of Pd (what I think is your plan<br>
anyway), you wouldn&#39;t have to find workarounds for issues exposed by<br>
running clients in the same instance.<br></blockquote><div style><br></div><div style>yes of course my patches stress the server a lot </div><div style>but it&#39;s only to delimit where the bug is.</div><div style>and at least it works for that :-)</div>

<div style><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
I figured you can only properly disconnect all clients with<br>
[net/tcpserver]. Unlike [iemnet/tcpserver], it has no &#39;disconnect&#39;<br>
method. So you have to disconnect each client separately.<br>
[iemnet/tcpserver] is supposed to disconnect all clients with<br>
&#39;disconnect&#39;, but actually the [iemnet/tcpclient]s seem to ignore it and<br>
keep their connected state (outlet 3 doesn&#39;t switch to 0). Finishing<br>
sessions seems generally to be still a problem with iemnet. Also when a<br>
client disconnects, the server often doesn&#39;t change the number of<br>
connected clients. The net library seems much more robust in this<br>
regard.<br>
<br>
I simplified your patches a lot and as simple as they are, they seem to<br>
work fine here. Note about the server: you need to disconnect all<br>
clients before you close the server patch. This will the leave the<br>
network socket in a clean state and you will be able to occupy that port<br>
immediately again. The client tries to connect at a rate of one try per<br>
second. In case it gets disconnected by the server, it waits 5 seconds<br>
before trying to connect again. This gives you time to disconnect all<br>
clients and shutdown the server properly.</blockquote><div><br></div><div style>hum, I can&#39;t be sure that all clients are properly disconnected because the pd where the server is could crash at anytime for lots of other reasons... </div>

<div style><br></div><div style><div>Behind that there is a shared memory id manager.</div><div>On the server side, I generate ids then try if I can get memory segment, if so I send this id to all clients that need it.</div>

<div>When a client gets connected, it asks for an id for a give path (a string like /video_server or /cam1) if it exist the server send it back to the client, if no, it generates a new id.</div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

 </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">
<br>
<br>
&gt; all of this is quite complex for a not so difficult task : I want to<br>
&gt; make several instance of Pd talking to each other on one machine<br>
&gt;<br>
&gt;<br>
&gt; I started with udpsend/udpreceive but I found no way to do broadcast<br>
&gt; on localhost<br>
<br>
</div>You mean broadcast on all ports? I don&#39;t think that something like that<br>
exists.<br></blockquote><div><br></div><div style>I mean listening several clients on the same port on the same machine (that is a server, right ?)</div><div style> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<div class="im"><br>
&gt; and I do need to have lots of clients<br>
&gt; multicasting is not a solution because it need to have a working<br>
&gt; networking interface<br>
<br>
</div>If you want to run many instances of Pd on localhost, then multicast<br>
can&#39;t help you. It is about sending data to many clients on different<br>
IPs at the same time. You want to send to many clients on localhost.<br>
<div class="im"><br>
&gt; then I tried udpserver which doesn&#39;t work (at least the version in the<br>
&gt; pd&#39;s SVN)<br>
&gt; then I switch to tcpserver and I got a lots of troubles...<br>
<br>
</div>Things look good as long as you think you only need streams. As soon as<br>
you figure out that you need to send packets between your instances of<br>
Pd, things get really complex wit [tcpserver].<br></blockquote><div><br></div><div style>no, I don&#39;t really need stream</div><div style>I choose [udpserver] because it&#39;s the only server in the iemnet&#39;s folder that works</div>

<div style>yep, it&#39;s a stupid reason... I should better try another udpserver somewhere else... :-)</div><div style><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<div class="im"><br>
&gt; I will try out iohannes version of iemnet and I&#39;ll also investigate<br>
&gt; those bugs<br>
<br>
</div>As of today, both libraries net and iemnet have known bugs. My examples<br>
use net because [iemnet/tcpserver] can&#39;t disconnect clients.<br>
<div class="im"><br>
&gt; but other (simpler) solutions are welcome :-)<br>
<br>
</div>See attachment. I tested them with Pd-extended 0.43.3 on Ubuntu 12.04<br></blockquote><div><br></div><div style>thanks for all</div><div style><br></div><div style>best</div><div style><br></div><div style>antoine </div>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<span class=""><font color="#888888"><br>
Roman<br>
<br>
</font></span></blockquote></div><br></div></div>