Discussion:
How to identify client connection (TCP Socket, C# 2.0)
(too old to reply)
maxima
2006-03-16 15:31:29 UTC
Permalink
Hi.

Is there recommended practice to identify incoming TCP connections?

For instance. My app has several threads each has connection to server. Each
of them transfer different type of data. So I'd like to keep them separate
(also to dont mix up fragmented TCP packets).

I stuck on implementation of effective identification system. How to assign
server working socket to corresponding thread.

After all I have to get the figure below :

Client:
- thread 1. socket.localendpoint = 192.168.0.100:2050
- thread 2. socket.localendpoint = 192.168.0.100:2051

Server:
- thread 1. workingSocket.remoteendpoint = 207.x.x.x:2050 <- real ip and
same port
- thread 2. workingSocket.remoteendpoint = 207.x.x.x:2051

Question 1: How properly (and in most simple way) implement handshake
between server and client to let server identify valid connection and reject
strangers.

Question 2: When client connects under private address (192.168.x) then
server outside will see real ip of private network gateway (say 207.x). Is it
true that client application will always present outside 207.x.x.x address
and not 207.x.x.y (is it possible for gateway to have more than 1 WAN
interface ?) ?

I mean how persistent and reliable would be identification by gateway's
address ??

Question 2.1: even in case of 3-stage handshake - I dont understand - how to
tell server which port will open client. I know that client socket gets port
number on socket.BeginConnect.... means that it is too late to tell server
this port number as it is about to connect server.........

Looks like server has to accept any connection and then wait for
confirmation with port number from client (before start send/receive on this
socket).... ??? dont like the idea really...

Any thoughts on that ?

Cheers
Arkady Frenkel
2006-03-16 16:03:59 UTC
Permalink
You can do it on data level only
Arkady
Post by maxima
Hi.
Is there recommended practice to identify incoming TCP connections?
For instance. My app has several threads each has connection to server. Each
of them transfer different type of data. So I'd like to keep them separate
(also to dont mix up fragmented TCP packets).
I stuck on implementation of effective identification system. How to assign
server working socket to corresponding thread.
- thread 1. socket.localendpoint = 192.168.0.100:2050
- thread 2. socket.localendpoint = 192.168.0.100:2051
- thread 1. workingSocket.remoteendpoint = 207.x.x.x:2050 <- real ip and
same port
- thread 2. workingSocket.remoteendpoint = 207.x.x.x:2051
Question 1: How properly (and in most simple way) implement handshake
between server and client to let server identify valid connection and reject
strangers.
Question 2: When client connects under private address (192.168.x) then
server outside will see real ip of private network gateway (say 207.x). Is it
true that client application will always present outside 207.x.x.x address
and not 207.x.x.y (is it possible for gateway to have more than 1 WAN
interface ?) ?
I mean how persistent and reliable would be identification by gateway's
address ??
Question 2.1: even in case of 3-stage handshake - I dont understand - how to
tell server which port will open client. I know that client socket gets port
number on socket.BeginConnect.... means that it is too late to tell server
this port number as it is about to connect server.........
Looks like server has to accept any connection and then wait for
confirmation with port number from client (before start send/receive on this
socket).... ??? dont like the idea really...
Any thoughts on that ?
Cheers
vlad
2006-03-16 16:34:11 UTC
Permalink
Hello Arkady,
Post by Arkady Frenkel
You can do it on data level only
Arkady
Thanx. I will do some kind of security tokens to be send in prior to connection
(thorugh 3d server which manages database, addmission lists etc).

But later on I think I would combine data-approach and sockets (like postponed
connections with checking ip, port and security token).


Also I found interesting thing as SO_CONDITIONAL_ACCEPT. Not sure I can access
that through .NET and it has withdraw of switching off internal (in TCP stack)
SYN attack defence
Vadym Stetsyak
2006-03-16 18:40:54 UTC
Permalink
Hello, vlad!

Didn't noticed the second post :8-) Read my answers on the 2nd post...

v> Thanx. I will do some kind of security tokens to be send in prior to
v> connection (thorugh 3d server which manages database, addmission lists
v> etc).

Are you working with raw sockets?

v> Also I found interesting thing as SO_CONDITIONAL_ACCEPT. Not sure I can access
v>that through .NET and it has withdraw of switching off internal (in TCP stack)
v>SYN attack defence.

Look at AcceptCallback delegate of the Socket.BeginAccept(...)
--
Regards, Vadym St
Arkady Frenkel
2006-03-17 09:25:25 UTC
Permalink
I don't think that it will be helpful in your case because you really don't
know which port client will use usually
Arkady
Post by vlad
Hello Arkady,
Post by Arkady Frenkel
You can do it on data level only
Arkady
Thanx. I will do some kind of security tokens to be send in prior to
connection (thorugh 3d server which manages database, addmission lists
etc).
But later on I think I would combine data-approach and sockets (like
postponed connections with checking ip, port and security token).
Also I found interesting thing as SO_CONDITIONAL_ACCEPT. Not sure I can
access that through .NET and it has withdraw of switching off internal (in
TCP stack) SYN attack defence.
vlad
2006-03-17 09:45:37 UTC
Permalink
Hello Arkady,
Post by Arkady Frenkel
I don't think that it will be helpful in your case because you really don't
know which port client will use usually
Arkady
Right.... Is there a technique to bind client socket to a particular port?

You said - "in your case" - does that mean - in some other case the problem
has no matter or doesnt exist?
Arkady Frenkel
2006-03-17 16:20:40 UTC
Permalink
That the same bind() as for server , but that mean that you'll have only one
client per computer if you'll go that way, and that what I meant "in your
case" ( I was sure that you talk about usual client . which use port
allocated by system )
Arkady
Post by vlad
Hello Arkady,
Post by Arkady Frenkel
I don't think that it will be helpful in your case because you really don't
know which port client will use usually
Arkady
Right.... Is there a technique to bind client socket to a particular port?
You said - "in your case" - does that mean - in some other case the
problem has no matter or doesnt exist?
Vlad
2006-03-17 16:35:36 UTC
Permalink
Hello Arkady,
Post by Arkady Frenkel
That the same bind() as for server , but that mean that you'll have only one
client per computer if you'll go that way, and that what I meant "in your
case" ( I was sure that you talk about usual client . which use port
allocated by system )
Arkady
Thank you. I really forgot that bind works for client. I've got your point
now. I can assign ports by myself from some hash(not only one socket per
client) but in this case I am still going to have problem with real IP (as
client doesnt know which one will be assigned by router)
Arkady Frenkel
2006-03-19 06:49:28 UTC
Permalink
That a problem of any gateway unless it gives opportunity to check external
IP ( like UPnP )
Arkady
Post by vlad
Hello Arkady,
Post by Arkady Frenkel
That the same bind() as for server , but that mean that you'll have only one
client per computer if you'll go that way, and that what I meant "in your
case" ( I was sure that you talk about usual client . which use port
allocated by system )
Arkady
Thank you. I really forgot that bind works for client. I've got your point
now. I can assign ports by myself from some hash(not only one socket per
client) but in this case I am still going to have problem with real IP (as
client doesnt know which one will be assigned by router).
Loading...