[Mono-dev] Need help with Sockets

Bernhard Herzog schwimmlehrer at gmail.com
Tue Aug 16 15:14:14 EDT 2005


Thanks Martin, this way it seems to work well.
I tried with well over 1000 connections and it went down to 0 after 
disconnecting. I still get that exception I submitted a bug report for, but 
that does not seems to be too much of a problem right now.

Once my server died with an assertion failure in socket-io.c in line 1084, 
don't know why this happened:

               if (mode == SelectModeRead) {
                        ret = _wapi_select (0, &fds, NULL, NULL, tvptr);
                } else if (mode == SelectModeWrite) {
                        ret = _wapi_select (0, NULL, &fds, NULL, tvptr);
                } else if (mode == SelectModeError) {
                        ret = _wapi_select (0, NULL, NULL, &fds, tvptr);
                } else {
                        g_assert_not_reached ();
                }

Thank you
Bernhard

----- Original Message ----- 
>From what I understand you are trying to ascertain whether your client
is still "alive". The way that IRC handles this is to have the server
send a "PING" message to the client every say 5 mins and the client is
obliged to send "PONG" before any further data is sent or received. If
no "PONG" is received within 120 secs say then the client is dead.

That's the way I would do it, rather than relying on the Socket to
know it has been closed...

Hope that helps,
Martin

On 8/16/05, Bernhard Herzog <schwimmlehrer at gmail.com> wrote:
> Thanks, that's interesting stuff.
>
> My application is a chat server, so I really need to know sooner than 2
> hours if the client is dead. On the other hand I have a web server and 
> don't
> want to introduce unnecessary traffic there. What is the right way to 
> handle
> this, right now I am just sending out some data - do I need to send it 
> back
> on the client (which would make things very complicated because I would 
> need
> timeouts) or is it sufficient to just send it out from the server to get 
> an
> exception? Or is there a problem in Mono, because with .Net it works
> flawlessly?
>
> Thanks again
> Bernhard
>
> ----- Original Message -----
> Good day.
>
> You can try to tune keepalive TCP parameters. These parameters can be
> setted via /proc file system. You can write values directly to
> pseudo-files, set them with sysctl utility, or add them to
> /etc/sysctl.conf. See man page for  sysctl for details.
>
> Keepalive parameters that could be useful for your case are these:
>
> net.ipv4.tcp_keepalive_intvl
> net.ipv4.tcp_keepalive_probes
> net.ipv4.tcp_keepalive_time
>
> For Suse Linux 9.2 they are setted as optimal for web-server:
> net.ipv4.tcp_keepalive_intvl = 75 - how long to wait between to probes
> for client alive (seconds)
> net.ipv4.tcp_keepalive_probes = 9 - how many probes to send before idle
> TCP connection force termination (units)
> net.ipv4.tcp_keepalive_time = 7200 - how long to wait on idle connection
> before check it for client alive (seconds)
>
> BTW, same for Windows defaults are: 1/5/7200.
>
> IMHO, you should change last parameter (2 hours) for something less. How
> long is depend on how long your connections should be keeped idle and
> how costly for you to open new connection.
>
>
> -----Original Message-----
> Hi!
>
> I have a Socket Server and Clients (see attached files). When
> disconnecting the clients the server does not receive exceptions on some
> of the clients. I have a cleanup routine that periodically checks the
> clients by sending some empty data. But this does not work for some of
> the clients (232 out of 360 connections are still "alive" on the server
> after closing the clients).
>
> Actually I created this client and server programs to test this
> particular
> bug:
> http://bugzilla.ximian.com/show_bug.cgi?id=75812
>
> But this problem does not show in my simplified test programs, but it
> does not work correctly nevertheless. The programs does work on MS .Net
> (BTW: The socket client program does not work on Mono for Windows, maybe
> this is the same problem that the MySql Connector is having on Windows
> in 1.1.8.3 -> but this is a different bug).
>
> Maybe someone can have a look, I would really appreciate that. I have
> not posted any bug reports yet (except for the one above). This is
> really a major issue for me (kind of a show stopper). Maybe I am doing
> something very wrong, I don't know. I am using 1.1.8.3 on Suse Linux
> 9.2.
>
> Thank you
> Bernhard
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>


-- 
Martin Hinks
http://www.m-s-d.net 




More information about the Mono-devel-list mailing list