Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
You probably want to ask why.
Because in order to talk to a certain hardware device,
It will only respond to my requests if the source computer uses port 7777.

I'm using VB2005, ya, it's old.

Here is a smattering of my code.
VB
Dim tcpClient As New System.Net.Sockets.TcpClient()
       tcpClient.Connect("192.168.1.4", 2000)
       Dim networkStream As NetworkStream = tcpClient.GetStream()
       If networkStream.CanWrite And networkStream.CanRead Then
           ' Send some data.
           Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("IE") & Chr(13)
           networkStream.Write(sendBytes, 0, sendBytes.Length)

Would i somehow use the following?
VB
Dim localEP As System.Net.EndPoint = "192.168.1.10:7777"
tcpClient.Client.Bind(localEP)
Posted
Updated 2-Dec-11 9:36am
v2

Just connect to the remote system like this :

C#
tcpClient.Connect("192.168.1.10", 7777)
 
Share this answer
 
Thanks,
It seems i tried that and had some problem with it.
Yesterday i found this code that worked.
Dim localIP As IPAddress = IPAddress.Parse("192.168.1.17")
Dim localPort As Int16 = 7775
Dim remoteIP As IPAddress = IPAddress.Parse("192.168.1.46")
Dim remotePort As Int16 = 7777
Dim remoteEP As IPEndPoint = New IPEndPoint(remoteIP, remotePort)
Dim localEP As IPEndPoint = New IPEndPoint(localIP, localPort)
Dim client As TcpClient = New TcpClient(localEP)
client.Connect(remoteEP)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900