Article View: borland.public.cppbuilder.internet.socket
Article #1509Re: Socket Connections through the Web and a router using NAT?
From: Remy Lebeau (TeamB)
Date: Wed, 10 Jan 2007 21:27
Date: Wed, 10 Jan 2007 21:27
68 lines
3828 bytes
3828 bytes
"chris" <computer@programmer.com> wrote in message
news:45a5472e$1@newsgroups.borland.com...
> The SocketServer program is running on 192.168.1.17 and listening on
the same port.
Are you absolutely sure of that? It is possible for a server to say
it is listening but actually isn't, or is listening on the wrong IP
adapter.
> It works on the LAN, so I know the server program is listening
> correctly.
Then the fault is likely with your router not forwarding the
connection properly.
> I really don't understand what you mean by "binding it".
A socket connection is uniquely identified by the combination of the
local IP/Port that it is bound to and the remote IP/Port that it is
connected to. When a client socket connects to a server, or a server
socket begins listening, it has to first bind itself to a local
IP/Port. This binding tells the OS which network adapter(s) to use
for the socket. A machine can have multiple adapters installed, so it
is important that the socket use the correct one(s).
> I do know that with the TServerSocket Component, when I
> set "ServerSocket1->Active = true;" the Socket begins to
> listen on its specified port at that moment.
Not necessarily at that exact moment. If you are using the server in
non-blocking mode (which is enabled by default), then the listening
begins asynchronously. The speed in which the server initializes
itself is tied to the speed in which the message queue processing
window messages. So it is possible that your client tries to connect
before the server socket is actually ready for it.
> All I do then with my Client Application is Set
> ClientSocket1->Host = "123.45.67.89:6111"
> (or "192.168.1.17" on the LAN, which works)
You can't specify the Port number in the Host property like that.
That type of syntax only works in third-party libraries that accept
URLs as input. That is not the case here. That in itself very well
may be why you are getting an error - TClientSocket (and the OS in
general) can't pasre a port number out of the Host like that). You
must separate the Host and Port properly, ie:
ClientSocket1->Host = "123.45.67.89";
ClientSocket1->Port = 6111;
> ClientSocket1->Active = true;
TClientSocket also has a non-blocking mode available (which is enabled
by default). Setting the Active property to true (or calling Open())
begins an asynchronous connection in that mode, again tied to window
message processing, and the connection is NOT established right away.
You cannot safely access the socket until the OnConnect event is
triggered in that situation.
> ClientSocket1->Socket->Connect(0);
Why are you using that? Get rid of that. Never call Connect()
directly. That is for TClientSocket's internal use only.
Gambit
Technical Details
Message-ID:
<45a55a60$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<45a5011b$1@newsgroups.borland.com> <45a5373f$1@newsgroups.borland.com> <45a5472e$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,f2ef1bbb95928174 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <45a5011b$1@newsgroups.borland.com> <45a5373f$1@newsgroups.borland.com> <45a5472e$1@newsgroups.borland.com> Subject: Re: Socket Connections through the Web and a router using NAT? Date: Wed, 10 Jan 2007 13:27:58 -0800 Lines: 70 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 75.83.34.171 Message-ID: <45a55a60$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1168464480 75.83.34.171 (10 Jan 2007 13:28:00 -0800) Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail