socket.EndAccept(ar) is Exclusive....any way to change?  
Author Message
Athrivarada





PostPosted: Tue Jan 02 01:52:57 CST 2007 Top

Visual Basic [VB] >> socket.EndAccept(ar) is Exclusive....any way to change? Hi, im making an AIM like server using TCP sockets, however i found a big
issue. when a socket is connected to (socket.EndAccept(ar)), its already
bound to a Port. since its bound, i cannot change its access to non
exclusive, but i need this port to still be open because i may need another
socket to connect on this port as well. how can i achieve this?
--
-iwdu15

Visual Studio264  
 
 
Tom





PostPosted: Tue Jan 02 01:52:57 CST 2007 Top

Visual Basic [VB] >> socket.EndAccept(ar) is Exclusive....any way to change? On 2007-01-02, iwdu15 <jmmgoalsteratyahoodotcom> wrote:
> Hi, im making an AIM like server using TCP sockets, however i found a big
> issue. when a socket is connected to (socket.EndAccept(ar)), its already
> bound to a Port. since its bound, i cannot change its access to non
> exclusive, but i need this port to still be open because i may need another
> socket to connect on this port as well. how can i achieve this?

You may need to explain this situation a little more clearly (maybe some short
code samples would be helpfull).

--
Tom Shelton
 
 
Martin





PostPosted: Tue Jan 02 02:50:51 CST 2007 Top

Visual Basic [VB] >> socket.EndAccept(ar) is Exclusive....any way to change? From what I remember of doing something similar a few years ago; You have a
'listening' socket and every time that socket detects an incoming connection
you open a new socket on a different port and make the connection on that
port. That way you can continue to listen on the original socket.

I don't have code samples to hand anymore i'm afraid.

HTH

"iwdu15" <jmmgoalsteratyahoodotcom> wrote in message
news:EMail@HideDomain.com...
> Hi, im making an AIM like server using TCP sockets, however i found a big
> issue. when a socket is connected to (socket.EndAccept(ar)), its already
> bound to a Port. since its bound, i cannot change its access to non
> exclusive, but i need this port to still be open because i may need
> another
> socket to connect on this port as well. how can i achieve this?
> --
> -iwdu15


 
 
Tom





PostPosted: Tue Jan 02 03:06:33 CST 2007 Top

Visual Basic [VB] >> socket.EndAccept(ar) is Exclusive....any way to change? On 2007-01-02, Martin <EMail@HideDomain.com> wrote:
> From what I remember of doing something similar a few years ago; You have a
> 'listening' socket and every time that socket detects an incoming connection
> you open a new socket on a different port and make the connection on that
> port. That way you can continue to listen on the original socket.

You are correct, that is how it is supposed to work - except, you don't open a
new socket. A new socket is returned to you via the accept method. I think
the op is confused about this - and is actually trying to communicate with the
client using the server socket. But, I'm not quite sure - hence the request
for clarification and code demonstrating the issue.

Some people fine the TcpListener/TcpClient classes useful - but to be honest,
I prefer to use the Socket class directly. That's a personal preference,
probably developed out of problems/bugs I experienced during the early beta's
:)

--
Tom Shelton
 
 
jmmgoalsteratyahoodotcom>





PostPosted: Tue Jan 02 18:28:01 CST 2007 Top

Visual Basic [VB] >> socket.EndAccept(ar) is Exclusive....any way to change? right, thats my problem. a Socket is given to me by the function
EndAccept(..), this socket is already bound to a port, so i cannot change it
to non-exclusive. is there any way to change that?
--
-iwdu15
 
 
Chris





PostPosted: Wed Jan 03 11:55:39 CST 2007 Top

Visual Basic [VB] >> socket.EndAccept(ar) is Exclusive....any way to change? "iwdu15" <jmmgoalsteratyahoodotcom> wrote
> Hi, im making an AIM like server using TCP sockets, however i found a big
> issue. when a socket is connected to (socket.EndAccept(ar)), its already
> bound to a Port. since its bound, i cannot change its access to non
> exclusive, but i need this port to still be open because i may need
> another
> socket to connect on this port as well. how can i achieve this?

Let's say you have a socket listening, on (for example) port 5222. You put
the socket into BeginAccept mode, and then out of the blue you get a
callback. In your callback method you call EndAccept, and get a reference to
a new socket (this is KEY!).

In the NEW socket, you call BeginReceive to start the whole receive process.
You now have a connected client.

On the original socket you call "BeginAccept()" again - this allows
additional users to connect. This algorithm is then repeated forever, and
you have a server that scales very well.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise, MVP C#
http://www.coversant.net/blogs/cmullins


 
 
jmmgoalsteratyahoodotcom>





PostPosted: Wed Jan 03 17:33:00 CST 2007 Top

Visual Basic [VB] >> socket.EndAccept(ar) is Exclusive....any way to change? yea, i realize this much. however, what i was confused about was wouldnt the
server throw an error the next time a connection attempt was made? like if
you try to bind more than one socket to a port without saying it does not
have exclusive access, an error is thrown. so when you receive a connection
attempt, the socket handed to you by EndReceive(...) is automatically
non-exclusive?
--
-iwdu15
 
 
Tom





PostPosted: Wed Jan 03 23:48:31 CST 2007 Top

Visual Basic [VB] >> socket.EndAccept(ar) is Exclusive....any way to change? On 2007-01-03, iwdu15 <jmmgoalsteratyahoodotcom> wrote:
> yea, i realize this much. however, what i was confused about was wouldnt the
> server throw an error the next time a connection attempt was made? like if
> you try to bind more than one socket to a port without saying it does not
> have exclusive access, an error is thrown. so when you receive a connection
> attempt, the socket handed to you by EndReceive(...) is automatically
> non-exclusive?

The socket handed to you by the EndReceive is a completly new and different
socket then the one that accepted the request. It is on a completly different
port, so you can have many client connect to the server sockets known port. The
conversation between the server and the client happens on the port allocated
to the new socket....

--
Tom Shelton
 
 
Bart





PostPosted: Thu Jan 04 06:26:12 CST 2007 Top

Visual Basic [VB] >> socket.EndAccept(ar) is Exclusive....any way to change? Hi,

"Tom Shelton" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> On 2007-01-03, iwdu15 <jmmgoalsteratyahoodotcom> wrote:
>> yea, i realize this much. however, what i was confused about was wouldnt
>> the
>> server throw an error the next time a connection attempt was made? like
>> if
>> you try to bind more than one socket to a port without saying it does not
>> have exclusive access, an error is thrown. so when you receive a
>> connection
>> attempt, the socket handed to you by EndReceive(...) is automatically
>> non-exclusive?
>
> The socket handed to you by the EndReceive is a completly new and
> different
> socket then the one that accepted the request.

That's right.

>It is on a completly different
> port, so you can have many client connect to the server sockets known
> port. The
> conversation between the server and the client happens on the port
> allocated
> to the new socket....

That's wrong. The new socket uses the same server port. A TCP server can
have many clients connected to the same port. When (connected) clients sent
packets to the server, the TCP stack can distinguish the received packets
based on the source IP and source port which is part of the IP/TCP header
that is sent along.

HTH,
Greetings

>
> --
> Tom Shelton


 
 
Tom





PostPosted: Thu Jan 04 15:22:12 CST 2007 Top

Visual Basic [VB] >> socket.EndAccept(ar) is Exclusive....any way to change?
Bart Mermuys wrote:
> Hi,
>
> "Tom Shelton" <EMail@HideDomain.com> wrote in message
> news:EMail@HideDomain.com...
> > On 2007-01-03, iwdu15 <jmmgoalsteratyahoodotcom> wrote:
> >> yea, i realize this much. however, what i was confused about was wouldnt
> >> the
> >> server throw an error the next time a connection attempt was made? like
> >> if
> >> you try to bind more than one socket to a port without saying it does not
> >> have exclusive access, an error is thrown. so when you receive a
> >> connection
> >> attempt, the socket handed to you by EndReceive(...) is automatically
> >> non-exclusive?
> >
> > The socket handed to you by the EndReceive is a completly new and
> > different
> > socket then the one that accepted the request.
>
> That's right.
>
> >It is on a completly different
> > port, so you can have many client connect to the server sockets known
> > port. The
> > conversation between the server and the client happens on the port
> > allocated
> > to the new socket....
>
> That's wrong. The new socket uses the same server port. A TCP server can
> have many clients connected to the same port. When (connected) clients sent
> packets to the server, the TCP stack can distinguish the received packets
> based on the source IP and source port which is part of the IP/TCP header
> that is sent along.

Your are correct of course. My bad. It was too late at night for me
to be thinking clearly. The local end point of the new socket is the
same as the servers, it is differentiated by the remote endpoint - the
ip:port from which the connection originated.

--
Tom Shelton