Why Multiple Socket Connections on one Connection....

Why Multiple Socket Connections on one Connection....

Post by Sergio Oliva » Wed, 24 Nov 1999 04:00:00



I'm using linux (rh6.1) connecting to NT server (or Workstation)...

I'm doing socket io... with the regular
bind/listing/accept/close, etc...

when I connect toNT, I always get two accepts....
The first one is valid, and I get the data there and back ok...

The second one basically connects and has no data and then
disconnects.... -- this is the one I have no idea why it's
happening...

Can anywone tell me why this is so...

Also...

I'm using the same perl script (also used C++) to connect to the NT
machine, and this works great everytime on NT....
When I connect using linux, I get a few valid  valid connections and
then I start gettting send or receive socket errors

This may be related to the second phantom socket getting an accept...
but I'd sure like to know why I'm getting this....

Thanks,
        sergio olivas

 
 
 

Why Multiple Socket Connections on one Connection....

Post by Charles Blackbu » Thu, 25 Nov 1999 04:00:00


On Tue, 23 Nov 1999 08:36:54 -0800, Sergio Olivas blurted:
Quote:>I'm using linux (rh6.1) connecting to NT server (or Workstation)...

>I'm doing socket io... with the regular
>bind/listing/accept/close, etc...

as you do when you are doing socket operations :-))

Quote:>when I connect toNT, I always get two accepts....
>The first one is valid, and I get the data there and back ok...
>The second one basically connects and has no data and then
>disconnects.... -- this is the one I have no idea why it's
>happening...
>Can anywone tell me why this is so...

maybe it's a feature of NT :)

R U using linux to connect to NT or the other way around?

how exactly are u making the connection?
ie: u must be doing something like this:

create socket
bind socket to port
listen for connections
accept connections
fork process to handle connection
go back to listening for connections

If you like, I could send you some simple server and client code if u
think that would help

--
Charles Blackburn
Summerfield Technology Limited - Official SuSE Reseller
Sponser Of the Birmingham (UK) Linux User Group


WWW: http://www.summerfieldtechnology.co.uk

 
 
 

Why Multiple Socket Connections on one Connection....

Post by Sergio Oliva » Fri, 26 Nov 1999 04:00:00


Yes... I'm connecting from Linux(client)  to NT( as server).
If I use NT or Win98 as clients, the the connections work normally.

What happens when I use linux to connect to NT, frequently, I get the
expected socket accept() when the client in linux connects. The NT
server goes off and starts off a thread (w/ the socket passed in) to
process the data.

However, immediately after, the NT server receives another accept.
When it then goes to read data, it finds that there is no data, and
the socket recv() returns 0... indicating non data/closed connection.

I have found out that when using perl (client) , if I put a 2 second
sleep after opening the  port, the bad connections are reduced to
about 1 in 10.... from about 1 in 3..

Both the C++ class and the Perl script exhibit the same problem on
linux... Both work properly when the same code is run from NT... It's
the same code....

Is there anything I'm missing on Delays, shutdown (I'm not using
this), or resetting ports that should be needed or done what I'm not
aware of???

The same perl script (unchanged) works properly on a tested solaris
box...

here's what I'm using to connect.... .

//////////////////////////////////////
package xx;


use Socket;
use Sys::Hostname;

$delimiter = "\001";

$MODE_BLOCK = 0;
$MODE_NOBLOCK = 1;

$ERR_HOST_NOT_SPECIFIED  = 1;
$ERR_PORT_NOT_SPECIFIED  = 2;
$ERR_SOCKET_NOT_OPEN     = 3;
$ERR_INVALID_LOGIN       = 4;
$ERR_SERVER_CLOSED_CONNECTION  = 5;
$ERR_SOCKET_ALREADY_OPEN = 6;

$ERR_AGENT_NOT_FOUND     = 50;
$ERR_SCRIPT_NOT_FOUND    = 51;
$ERR_CANT_CONNECT_TO_AGENT = 52;
$ERR_AGENT_CONNECTION_LOST = 53;

$ERR_SOCKET_CONNECTION_FAILED = 80;
$ERR_SOCKET_BIND_FAILED = 81;
$ERR_SOCK_INITIALIZATION_FAILED = 99;

$ERR_PREFIX = "!!--##";

$SIG{'Int'} = 'dokill';

sub dokill
{
    kill 9, $child if $child;

Quote:}

sub new
{
        return bless {};

Quote:}

sub Open
{
   my $self = shift;

   # Initialize Local copies for simplicity  
   my $debug = $self->{m_debug};

   # Initialize

   $self->{m_lasterror} = 0;
   $self->{m_gwCon} = 0;
   $self->{m_output} = "";
   $self->{m_bOpen} = 0;

   ($name, $aliases, $proto) = getprotobyname('tcp');
   ($name, $aliases, $port) = getservbyname($port,'tcp') unless $port
=~/^\d+$/;

   if ($server eq "")
   {
      $self->{m_lasterror} = $ERR_HOST_NOT_SPECIFIED;
      return $self->{m_lasterror};
   }
   if ($port == 0)
   {
      $self->{m_lasterror} = $ERR_PORT_NOT_SPECIFIED;
      return $self->{m_lasterror};
   }

   if ($debug)
   {    
      print "Using port $port to connect to server on host
$server...\n";
   }

  ($name,$aliases,$type,$len,$thisaddr) = gethostbyname(hostname());
  ($name, $aliases,$type,$len,$thataddr) = gethostbyname($server);

   if (socket(S,AF_INET, SOCK_STREAM, $proto))
   {
      if ($debug)
      {
         print "Socket creation succeeded.\n";
      }
   }
   else
   {
      $self->{m_lasterror} = $ERR_SOCK_INITIALIZATION_FAILED;
      return $self->{m_lasterror};
   }

  $sockaddr = 'S n a4 x8';
  $this = pack($sockaddr, AF_INET, 0, $thisaddr);
  $that = pack($sockaddr, AF_INET, $port, $thataddr);

   if (bind(S, $this))
   {
      if ($debug)
      {
         print "Bind succeeded.\n";
      }
   }
   else  
   {
      $self->{m_lasterror} = $ERR_SOCKET_BIND_FAILED;
      return $self->{m_lasterror};
   }

   if (connect(S, $that))
   {
      if ($debug)
      {
         print "Connect succeeded.\n";
      }
   }
   else
   {
      $self->{m_lasterror} = $ERR_SOCKET_CONNECTION_FAILED;
      return $self->{m_lasterror};
   }

   select(S);
   $| = 1;

   select(STDOUT);

   $slogin = $username . "\t" . $password;
   print S $slogin;

   while(sysread(S,$output,65000) == 0)
   {
      sleep(1);
   }

   if ($output eq "1")
   {
      $self->{m_gwCon} = S;
      $self->{m_bOpen} = 1;
      return 0;
   }
   else
   {
      $self->{m_lasterror} = $ERR_INVALID_LOGIN;
      return $self->{m_lasterror};
   }

Quote:}

////////////////////////////////////

When this connects, it sends a username and password, then is supposed
to receive a "1" or a "0" to indicate whether the username is
valid.... I haven't really seen anything wrong w/ the code, since it
does work on the pc w/out any changes...

Is there any type of Port configuration changes/initialization I might
need???

Oh, please do send me the examples you mentioned....

thanks,
        sergio olivas

On Wed, 24 Nov 1999 22:01:36 +0000,


>On Tue, 23 Nov 1999 08:36:54 -0800, Sergio Olivas blurted:
>>I'm using linux (rh6.1) connecting to NT server (or Workstation)...

>>I'm doing socket io... with the regular
>>bind/listing/accept/close, etc...
>as you do when you are doing socket operations :-))

>>when I connect toNT, I always get two accepts....
>>The first one is valid, and I get the data there and back ok...
>>The second one basically connects and has no data and then
>>disconnects.... -- this is the one I have no idea why it's
>>happening...
>>Can anywone tell me why this is so...
>maybe it's a feature of NT :)

>R U using linux to connect to NT or the other way around?

>how exactly are u making the connection?
>ie: u must be doing something like this:

>create socket
>bind socket to port
>listen for connections
>accept connections
>fork process to handle connection
>go back to listening for connections

>If you like, I could send you some simple server and client code if u
>think that would help

 
 
 

Why Multiple Socket Connections on one Connection....

Post by Sergio Oliva » Sun, 28 Nov 1999 04:00:00


ok... the problem i was had to do with the environment I was using,
instead of linux...

I was connecting to the linux box via the NAT port mapping software
sygate, which would route packets destined to port 80 coming in to the
linux box...which was running apache that would then start the cgi
script that was having the problem...

I seems a wierd combination of the two would cause the problem.

I got a second IP address from my cable company (cox), and put the
linux box directly on the net bypassing the Sygate software, for
testing.... and the problem went away....

sergio olivas

 
 
 

1. multiple xDSL connections from one ethernet connection.

Weird request I guess.

I have a classroom and access to an ethernet socket on the wall.

I would like each student to have their own DSL line to
their desk so they can install and configure their own DSL
modem pci card.  Then ideally go through the rest of the
course using that as their internet connection for
downloading software.

Since they would (or should) all be downloading the same
software, a web cache machine could be placed at the
ethernet connection.

I never get to see this side of the ADSL hardware. It all
happens back at the local telephone exchange, but this is
what I'd like to achieve.

It easy enough to turn a linux beige-box into an ethernet
switch, and I would like to think I could do the same but
with DSL modem cards instead of ethernet cards, but I need
pointers so some software here.

What problems can anyone forsee?

Cheers
Andy  Richardson

2. getting my cdrom to work

3. Implementing multiple channels over one socket connection

4. The close system call

5. Opening a socket connection while in a socket connection.

6. Lost 2000 Megs

7. One NFS connection fine, one NFS connection slow

8. pacct and acct-6.3 utilities, and lastcomm

9. Multilink PPP with one fixed connection, and one PPPoE connection

10. PPP connection works well ,while SLIP connection doesn't work,why and how?

11. How to listen for socket connection on multiple interfaces.

12. Q: Sockets - handling multiple connections

13. why won't old socket connections disappear?