Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
IO::Socket::INET same port

Posted by kenshail (kenshail), 22 June 2005
Problem with IO::Socket::INET.

If a client reconnects using the same port (actually the same port as the server) after a few normal open/close connections the client often gets refused.
The server appears to not reply to the client's first SYN.

If the client is allowed to chose its own (different) port each time things work fine, but that is not practical in this case.

I have included the sever initialisation and accept script below.

At a guess it is something to do with 2MSL or DOS protection, but probably I am wrong.

I am using it in a LAN environment , not connected to the internet therefore DOS attacks are not an issue.

The application simply listens for clients to send short text strings and then the clients disconnect themselves normally, but this problem occurs quite often. The refused clients then have to time-out and get a successful connection later.

Has anyone seen this before and is there a simple solution?

Someone snugly demonstrated that a server written in VB using Winsock worked
perfectly where as my script written on Activestate perl failed!

I am only coming to this forum after many hours of failed research and failed tests.

Thanks in advance to anyone who can help.


sub openListner
{
 if ($listenSock = new IO::Socket::INET (LocalAddr => $myIP,
                                  LocalPort => 8006,
                                  Proto     => 'tcp',
                                  ReuseAddr => 1,
                                  RueusePort =>1,
                                  Listen    => ($maxClients + 5)) ) # Just
a few extra!
 {

 #this bit of magic stops the socket from blocking in Winoze ONLY.
  my $temp = 1;
 ioctl ($listenSock, 0x8004667E, \$temp); # set non-blocking

 #This stops the socket from blocking in Linux ONLY
   $listenSock->blocking(0);

  print RX "listening on $myIP\n";
  }
}


$main->repeat(250=>\&run);
This is called by a  Tk mainwindow every 250 Milliseconds. RX prints to a Tk Textbox

sub run
{
   while($new_sock = $listenSock->accept())
 {
  print RX "peer=".$new_sock->peerhost."\n";
  $rxText="";
  do
    {
      $new_sock->recv($rx_txt,4095);
      $rxText.=$rx_txt;
     } until (!length($rx_txt));

     print RX "$rxText\n\n";
     print LOGFILE "$rxText\n";
    $new_sock->close();
   }
}





Posted by admin (Graham Ellis), 23 June 2005
Oh help, Ken ... this is one of those tricky "ultra-niche" questions that crops up occasonally where the only honest answer I can give you is "not seen that ... don't know".    The best I can offer / suggest is to offer to put my head together with yours and see if we could work something out - I do know you're not far from out base and if you felt it was worth coming over for an hour of two one evening to see if we could research it / sort it, I would be open to that.    Scheduling in the next couple of weeks may be tricky as I'm out and about, but do email me if interested in taking this up.

Posted by kenshail (kenshail), 31 July 2005
Graham
Thanks for your reply.
I believe that I have found the answer but can not be sure without some authorative knowledge of what happens in the IO::Socket::INET module and deeper-down:

If appears that a client trying to reconnect on the same IP address and same port during a preset time  is regarded by the server as late-arriving packets from a session that is closed. The server therefore does not accept the connection.

This must be one of the reasons for the common practice of clients chosing a different port for each new connection.

I will try and get to visit you before long. (by prior appointement of course).
Ken

Posted by Custard (Custard), 31 July 2005
It's not the OS TCP/IP stack trying to protect against SYN flood attacks is it?

Maybe sending that many connections from the same IP kicks in something?  (linux has this protection configurable I think)

Just a thought.

B



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho