Sockets local entrypoint

  • Thread starter Thread starter Roger
  • Start date Start date
R

Roger

I am using a Socket object to communicate to a host over TCP/IP.
All works fine but I need to add functionality.
My computer has 2 network cards, each with its own IP address and I
want to communicate using only one of them.

I do the following:
MySocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp)
MySocket.Bind(LocalEP)
MySocket.Connect(EndPoint)
CommStream = New NetworkStream(HRDConnSocket, IO.FileAccess.ReadWrite)

.... then I read and write to/from the CommStream object.

LocalEP is an IPEndPoint object to the IP address, port 0 of one of
the network cards on my computer.
EndPoint is an IPEndPoint object to the host IP and port.

What happens is that the .Connect method connects through the proper
network card but all reads and writes occur on the other card.
I was expecting that the NetworkStream would obey what was set on the
socket but it does not seem to work like that.
If anyone can help, thanks
 
Hi Roger,

Sorry, I can't answer your query - it's not my area. :-(

However, for future reference, if you make an adjustment to a query,
rather than submitting it as a new query, could you make it a response to your
original ?

It helps us. :-)

Regards,
Fergus
 
Dont know the exact answer to your question, but looking at your code, you
use HRDConnSocket in the New NetworkStream command.... Looking in the SDK
Docs, shouldn't it be New NetworkStream(MySocket,...)???
 
Your right (and I changed it in the post), but this is just a typo in
this posting, I renamed the socket to MySocket to make it simpler but
forgot to replace that occurrence.
 
Hmm... if anyone has a response, or if you figure it out Roger, please post
it to the newsgroup, I am definitely interested in the answer for a section
of my upcoming project.
 
Yes you are right, I actually have MySocket in there. It is a typo
when typing my post.
 
Back
Top