Click to See Complete Forum and Search --> : 1 Server, 2 Clients & 2 different ports


FredoSP
July 29th, 2002, 08:45 AM
Hello,

I'll keep it short and sweet. I'm writing a program to act as a
server. This server will accecpt two (2) client connections. I have
two objects of the TCPListener Class that listen on two local ports (100 and 101 on my PC as the localhost 127.0.0.1). The problem that I'm running into is when the AcceptSocket() function waits for a connection it blocks. Futhermore, if its waiting for a connection from Port 100 and if a client with Port 101 decides to connect, it will not connect because its waiting for 100. Threading maybe one way to solve this. I want to be able to listen at the sametime for a connection on Port 100 and 101 and then once that is established go do other things.

Thanks - Fred

Arild Fines
July 29th, 2002, 09:07 AM
Use the Socket class directly and use BeginAccept instead of Accept. Check the docs.
Why do you need 2 different server ports anyway? You can service an unlimited number of clients on one server port, since the communication happens on a randomly assigned port once the initial handshaking is done(Example: High performance web servers only listen on port 80).

FredoSP
July 29th, 2002, 05:33 PM
Thanks!! I convinced the person that we could only use one port and have all clients connectiong to it on that. Thanks!!

I have another question if you don't mind ... its in another thread.:D

jparsons
July 30th, 2002, 09:48 AM
Originally posted by FredoSP
Thanks!! I convinced the person that we could only use one port and have all clients connectiong to it on that. Thanks!!

I have another question if you don't mind ... its in another thread.:D

Also, why are you connecting on such low number ports? Connecting on a port so low as that means that you must have Root/Administrative access to the computer and are running your server with such permissions. If you have a buffer overflow it can result in a root hole on your machine(assuming you could buffer overflow .NET like that). I would suggest running your server as a nonprivledge user on a port about 1600 ( or is it 1200, I keep forgetting )

Arild Fines
July 30th, 2002, 01:06 PM
Originally posted by jparsons


Also, why are you connecting on such low number ports? Connecting on a port so low as that means that you must have Root/Administrative access to the computer and are running your server with such permissions.

Does that really go for NT computers as well?

I would suggest running your server as a nonprivledge user on a port about 1600 ( or is it 1200, I keep forgetting )
1024 is the upper limit for the restricted ports.

jparsons
July 31st, 2002, 09:35 AM
Originally posted by Arild Fines

Does that really go for NT computers as well?


Hmm. I would think that it does but I can't say for 100% sure. Most users on NT run as Admin anyways ( hence the massive security exploits ) so connecting to ports less than 1024 wouldn't be as much of a hassle as it would be in a Unix environment. however the security exploits are most likely still there.


1024 is the upper limit for the restricted ports.

I don't know why I couldn't remember that. I knew my answer was wrong when it wasn't a power of 2 :)