Author | Topic: Quetion on TCP/IP Port ? | |
---|---|---|
Shum [MingYik] | Quetion on TCP/IP Port ? on Wed, 22 Dec 2004 00:39:29 +0800 Hello All, 1.) I set up a TCP/IP Server on a PC (with IP ie. 192.168.0.5) and listen to port 1042 2.) Then connect to the Server ( 192.168.0.5) from another PC (with IP ie. 192.168.0.6) it show connection success by SocketOpen( SOCK_STREAM, "192.168.0.3", 1042, @nErr) However If change the port as SocketOpen( SOCK_STREAM, "192.168.0.3", 1043, @nErr) Then PC(with IP i.e.. 192.168.0.6) fail to make connection ?? then I check the document of ASINET ... it show me: nPort parameter as follow: <nPort> This is the numeric port number on the local computer to bind the socket to. Whats wrong ? Shum www.mingyik.com | |
Phil Ide | Re: Quetion on TCP/IP Port ? on Tue, 21 Dec 2004 17:10:37 +0000 Shum, > 2.) Then connect to the Server ( 192.168.0.5) from another PC (with IP ie. > 192.168.0.6) > it show connection success by SocketOpen( SOCK_STREAM, "192.168.0.3", > 1042, @nErr) No, you should use SocketConnect() to connect to another machine. Regards, Phil Ide *************************************** * Xbase++ FAQ, Libraries and Sources: * * goto: http://www.idep.org.uk/xbase * *************************************** Everything in excess! Moderation is for monks. | |
Shum [MingYik] | Re: Quetion on TCP/IP Port ? on Wed, 22 Dec 2004 15:58:04 +0800 Hello Phil Ide, > No, you should use SocketConnect() to connect to another machine. Server PC (192.168.0.5) listen to port 1042 I try: ... But Fail If (nSocket := SocketNew( AF_INET, SOCK_STREAM, 0, @nErr) ) <> 0 SocketConnect( nSocket, AF_INET, "192.168.0.5", 1043, @nErr Endif If I change the port into 1042 ... it's success What I am try to do is that: I want the client PC (by using port 1043) to connect to server (with listen to port 1042) Is it possible ? Shum www.mingyik.com "Phil Ide" <phil@idep.org.uk> ???????:119slqarrf9lu$.dlg@idep.org.uk... > Shum, > >> 2.) Then connect to the Server ( 192.168.0.5) from another PC (with IP >> ie. >> 192.168.0.6) >> it show connection success by SocketOpen( SOCK_STREAM, >> "192.168.0.3", >> 1042, @nErr) > > No, you should use SocketConnect() to connect to another machine. > > Regards, > -- > Phil Ide > > *************************************** > * Xbase++ FAQ, Libraries and Sources: * > * goto: http://www.idep.org.uk/xbase * > *************************************** > > Everything in excess! Moderation is for monks. | |
Martin Altmann | Re: Quetion on TCP/IP Port ? on Wed, 22 Dec 2004 10:38:57 +0100 Shum, no! If you expect somebody to come through the left door you open the left door - the right door keeps closed! So the guy will not be able to get through the right door into your home. If you want to achieve what you are trying to do you would have to either: - change the ports on both ends to the same number - install/set up a router (or a simple NAT I would guess), through which the traffic from this specific client is going to your server. There you can switch ports, i.e. if inbound traffic is coming through port 1043 it is switched to port 1042 and vice versa (outbound traffic through port 1042 is switched to port 1043). HTH, Martin "Shum [MingYik]" <shum@mingyik.com> schrieb im Newsbeitrag news:eNK1Cw$5EHA.6380@S15147418... > Hello Phil Ide, > > I want the client PC (by using port 1043) to connect to server (with > listen to port 1042) > Is it possible ? | |
Shum [MingYik] | Re: Quetion on TCP/IP Port ? on Wed, 22 Dec 2004 17:56:28 +0800 Hello Martin Altmann, thanks for reply! : then ... the doc of ASINET is mis leading: for <nPort> parameter <nSocket> This is a numeric socket descriptor previously created with SocketNew(). <nAddressFamily> This parameter specifies the adress family to which the socket belongs to. Windows only supports #define constant AF_INET as value, which is the default. <xRemoteAddress> The remote address can be specified either as a numeric address in network byte order, or as a character string. The latter can be coded as the DNS name of the computer running the remote process, or as the IP address in form of a dotted octet string. <nPort> This is the numeric port number on the local computer to bind the socket to. <nError> If this parameter is passed by reference to the function, it gets assigned a numeric error code when the function fails. #define constants beginning with WSAE are available in the file ASINETC.CH to identify an error condition. <xRemoteAddress> is for remote Server IP is it roght ? <nPort> : is for local computer IP's port ............... ????? Shum www.mingyik.com "Martin Altmann" <Altmann@altem.de> glsD:fLKOmpA6EHA.1932@S15147418... > Shum, > no! If you expect somebody to come through the left door you open the left > door - the right door keeps closed! So the guy will not be able to get > through the right door into your home. > If you want to achieve what you are trying to do you would have to either: > - change the ports on both ends to the same number > - install/set up a router (or a simple NAT I would guess), through which > the traffic from this specific client is going to your server. There you > can switch ports, i.e. if inbound traffic is coming through port 1043 it > is switched to port 1042 and vice versa (outbound traffic through port > 1042 is switched to port 1043). > > HTH, > Martin > > "Shum [MingYik]" <shum@mingyik.com> schrieb im Newsbeitrag > news:eNK1Cw$5EHA.6380@S15147418... >> Hello Phil Ide, >> >> I want the client PC (by using port 1043) to connect to server (with >> listen to port 1042) >> Is it possible ? > > | |
Martin Altmann | Re: Quetion on TCP/IP Port ? on Wed, 22 Dec 2004 11:08:35 +0100 Shum, I am not using asinet. But to your assumptions: "Shum [MingYik]" <shum@mingyik.com> schrieb im Newsbeitrag news:gYXrVyA6EHA.5064@S15147418... > Hello Martin Altmann, > > <xRemoteAddress> is for remote Server IP is it roght ? yup, 'tis. > <nPort> : is for local computer IP's port ............... ????? nope, 'tisn't! nport is the port you will have to get through to reach the "server" Imagine yourself being in a big house (a very big house to be honest!) with hundreds of thousands front doors! As you will not be able to manage all the doors you have to lock all of them and only unlock the ones you are expecting guests to knock on. So you have one front door for your girl friend, one for their parents, one for your friends, one for your parents, .... Whenever someone comes through a door you do know that it is somebody (more or less) important and "handle" him/them accordingly. HTH, Martin | |
Shum [MingYik] | Re: Quetion on TCP/IP Port ? on Wed, 22 Dec 2004 18:04:18 +0800 Another question is ... 1.) I want to be the server and client "run"on the Same PC 2.) Other PC(s) also only "run" the clients only 3.) All With different IP Address But Same port (i.e.: 1042) Let say Clients (including the one on the server) connect to the Server (with different thread on each connection) see... will client (which on the server) take away communication message form Server ? Shum www.mingyik.com "Martin Altmann" <Altmann@altem.de> glsD:fLKOmpA6EHA.1932@S15147418... > Shum, > no! If you expect somebody to come through the left door you open the left > door - the right door keeps closed! So the guy will not be able to get > through the right door into your home. > If you want to achieve what you are trying to do you would have to either: > - change the ports on both ends to the same number > - install/set up a router (or a simple NAT I would guess), through which > the traffic from this specific client is going to your server. There you > can switch ports, i.e. if inbound traffic is coming through port 1043 it > is switched to port 1042 and vice versa (outbound traffic through port > 1042 is switched to port 1043). > > HTH, > Martin > > "Shum [MingYik]" <shum@mingyik.com> schrieb im Newsbeitrag > news:eNK1Cw$5EHA.6380@S15147418... >> Hello Phil Ide, >> >> I want the client PC (by using port 1043) to connect to server (with >> listen to port 1042) >> Is it possible ? > > | |
Phil Ide | Re: Quetion on TCP/IP Port ? on Wed, 22 Dec 2004 11:05:13 +0000 Shum, > 1.) I want to be the server and client "run"on the Same PC > 2.) Other PC(s) also only "run" the clients only > 3.) All With different IP Address But Same port (i.e.: 1042) > > Let say Clients (including the one on the server) connect to the Server > (with different thread on each connection) > > see... will client (which on the server) take away communication message > form Server ? Yes, you can listen on port 1042 on 192.168.0.5, and you can connect to it from multiple clients on the same machine. At the same time, you can connect to it from other machines. Only the listening socket will recieve connections. To understand this process you have to know how sockets work. You can create a socket and bind it to a port (e.g. 1042) and an address - usually this address is the local network machine address, but can be a public IP address. When a client connects, the client opens a socket with an ADDRESS of [machine:port] - it doesn't actually consume the port. After the listening socket has accepted the connection, the server generates a new socket which is bound to a different (and effectively random) port, and the client is informed of the new address. From now on, the client and server communicate through this new socket, and the listening socket on port 1042 goes back to listening. So only the listening socket is bound to a named port. Think of a socket as a construct with properties: 1. Local Machine Address 2. Socket ID 3. Remote Machine Address 4. Port 5. Socket Type (IP, UDP etc.) The Socket ID is NOT related to the port, and each time you create a new socket, you get a unique ID. When you set a socket to listening, it registers the Socket ID with the sockets handler application (wininet.dll etc), and only one socket can be registered per port. When a connection request comes from a client application, the socket handler application looks up the socket id registered on the required port and retrieves the socket handle. It can then pass data to the socket, which in turn is handled by the server application. Regaards, Phil Ide *************************************** * Xbase++ FAQ, Libraries and Sources: * * goto: http://www.idep.org.uk/xbase * *************************************** "My God, it's full of stores!" - 2001: A Shopping Odyssey | |
Shum [MingYik] | Re: Quetion on TCP/IP Port ? on Wed, 22 Dec 2004 23:09:59 +0800 Hello Phil Ide & Martin Altmann, Thanks for make me clear for the concept on TCP/IP 's port ! Shum www.mingyik.com "Phil Ide" <phil@idep.org.uk> ???????:1ixks6zx6yfd7$.dlg@idep.org.uk... > Shum, > >> 1.) I want to be the server and client "run"on the Same PC >> 2.) Other PC(s) also only "run" the clients only >> 3.) All With different IP Address But Same port (i.e.: 1042) >> >> Let say Clients (including the one on the server) connect to the Server >> (with different thread on each connection) >> >> see... will client (which on the server) take away communication message >> form Server ? > > Yes, you can listen on port 1042 on 192.168.0.5, and you can connect to it > from multiple clients on the same machine. At the same time, you can > connect to it from other machines. > > Only the listening socket will recieve connections. To understand this > process you have to know how sockets work. > > You can create a socket and bind it to a port (e.g. 1042) and an address - > usually this address is the local network machine address, but can be a > public IP address. > > When a client connects, the client opens a socket with an ADDRESS of > [machine:port] - it doesn't actually consume the port. After the > listening > socket has accepted the connection, the server generates a new socket > which > is bound to a different (and effectively random) port, and the client is > informed of the new address. From now on, the client and server > communicate through this new socket, and the listening socket on port 1042 > goes back to listening. So only the listening socket is bound to a named > port. > > Think of a socket as a construct with properties: > > 1. Local Machine Address > 2. Socket ID > 3. Remote Machine Address > 4. Port > 5. Socket Type (IP, UDP etc.) > > The Socket ID is NOT related to the port, and each time you create a new > socket, you get a unique ID. When you set a socket to listening, it > registers the Socket ID with the sockets handler application (wininet.dll > etc), and only one socket can be registered per port. When a connection > request comes from a client application, the socket handler application > looks up the socket id registered on the required port and retrieves the > socket handle. It can then pass data to the socket, which in turn is > handled by the server application. > > Regaards, > -- > Phil Ide > > *************************************** > * Xbase++ FAQ, Libraries and Sources: * > * goto: http://www.idep.org.uk/xbase * > *************************************** > > "My God, it's full of stores!" - 2001: A Shopping Odyssey | |
Phil Ide | Re: Quetion on TCP/IP Port ? on Wed, 22 Dec 2004 10:44:34 +0000 Shum, >> No, you should use SocketConnect() to connect to another machine. > > Server PC (192.168.0.5) listen to port 1042 > > I try: ... But Fail > If (nSocket := SocketNew( AF_INET, SOCK_STREAM, 0, @nErr) ) <> 0 > SocketConnect( nSocket, AF_INET, "192.168.0.5", 1043, @nErr > Endif > > If I change the port into 1042 ... it's success > > What I am try to do is that: > > I want the client PC (by using port 1043) to connect to server (with listen > to port 1042) > Is it possible ? No, you must use the same port as the server. However, a connecting socket does not consume a port, so you can have multiple sockets all onnecting on the same port, to one or more servers. You can only use one socket to listen on per machine though. Regards, Phil Ide *************************************** * Xbase++ FAQ, Libraries and Sources: * * goto: http://www.idep.org.uk/xbase * *************************************** Catchup: A hair ball |