Re: How to identify client connection (TCP Socket)



On question 2 - the answer is actually NO. In the presense
of symmetric NAT, the same client may connect to the server
using different public IP addresses.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

"Vadym Stetsyak" <vadym_s@xxxxxxx> wrote in message
news:uo3SkiSSGHA.5468@xxxxxxxxxxxxxxxxxxxxxxx
Hello, vlad!

v> Is there recommended practice to identify incoming TCP connections?

AFAIK each TCP connection, according to TCP RFC, is identified uniquely
with
RemoteHost : RemotePort <-> LocalHost : LocalPort

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

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

If I understood you correctly you have some state that is in separate
thread, and when the request from client arrives you
wake up appropriate thread?

If it is so then...

it is bad idea to bind a thread to particular remote host due to
scalability issues...
You can use a dictionary to get needed data

Smth like

Dictionary<RemoteEndPoint, AssociatedClientState> jobsDictionary;

v> After all I have to get the figure below :

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

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

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

It is better to implement custom authentication mechanism, because clients
IP can be spoofed, thus
introducing security hole.

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

Yes

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

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

Why? You can bind socket to specific port and IP. Socket.Bind(....);

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

Why do you have to think about how TCP connection is initiated?

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com


.



Relevant Pages

  • Re: Unable to print to networked printer - get access denied messa
    ... Check the permissions on the server assuming the client has a true RPC ... How is the Standard TCP/IP port configured for the device? ...
    (microsoft.public.windowsxp.print_fax)
  • Re: interfaces lo:1 lo:2 lo:3? (for remote ssh tunnels)
    ... That's the problem tunneling (port forwarding) solves. ... >>can't get past the client firewall. ... > I don't understand why the server would be making the ... server initiates another connection to the client -- in this ...
    (Debian-User)
  • Re: Remote Connection Issue
    ... through port number 3389 and a workstation on the LAN through port number ... I understand that you want to allow a LAN client ... and you have configured server publishing rule ... > By default Terminal Server and Windows 2000 Terminal Services uses TCP ...
    (microsoft.public.windows.server.sbs)
  • Re: RealVNC
    ... Default listening port for RealVNC server that runs on the machine on which ... Then there is default Java listening port on port 5800 on the client machine ...
    (microsoft.public.windows.server.sbs)
  • Re: Redirecting data sent to a local printer to another host and port on the network
    ... All client workstations have access to the ... simply redirecting netcat traffic on port 9100 to port 515 on ... Only LPR clients talk to LPD print server daemons. ... >workstation at the branch site where the print job originated. ...
    (comp.unix.sco.misc)