Winsock: How to receive data when you cant bind to a port?
Im using a winsock control in my application to read data that comes in on a specific IP. The remote IP is static, as is the remote port. However, it binds to a different local port every time. Is there a way to 'override' this issue? Is there a way in VB6 to allow the incoming data to randomly select the portit wants, and then have the application bind to it?
Im using the following code, but the 'Bind' value cannot be predefined. Is there a way I could allow the application to randomize the choice of local ports? Sometimes it connects to port 1045, sometimes 1046, or 1048 etc.
With Winsock1
.RemoteHost = "xxx.xxx.xxx.xxx"
.RemotePort = 1809
.Bind 1045
End With
Thanks
Re: Winsock: How to receive data when you cant bind to a port?
How do you determine what port it is binding to now?
Re: Winsock: How to receive data when you cant bind to a port?
Hi Hack..
I cant determine the port. However, the data is also used by another application. And when running that application, i have used port sniffer to see that the incoming port is different every time. And when that application is running, I cannot use my winsock control to bind to that port, since its already in use.
Is there a way to use that port while its already in use, so that I can import that data stream into my own application as well?
Re: Winsock: How to receive data when you cant bind to a port?
Some other application is reading the port? Then you can't get the data from the port, you have to get it from the application (which has to send it to you). There's no "splitter" for IP ports.
Re: Winsock: How to receive data when you cant bind to a port?
It is possible to specify a value for LocalPort on a TCP client socket, but it is generally undesireable and causes problems.
The real question is why on Earth you'd want to? TCP clients are normally assigned a port from the ephemeral pool automatically by TCP. This should have no impact on sucessfully using the resulting connection. This is just how TCP works.
What are you trying to do? Your comments almost seem to suggest you want to try to "tap into" another application's TCP connection.