-
COM and TCP
Can anyone help me get started with a few lines of code that will help my app catch data inbound tcp data and route to an outbound com port?
I want the app to catch a "1" via tcp which the app will identify and send a corresponding string to a specified com port.
I think i've got the com portion down. I just need to know how to integrate the TCP portion. any pointers are appreciated.
Thanks
CM
-
Re: COM and TCP
"COM" here means "Component Object Model" and not anything to do with serial ports.
Sorry.
-
Re: COM and TCP
Is this .net, vb6, etc?
Have you looked at the Winsock Control?
-
Re: COM and TCP
Use the Winsock control of vb. you can use it for both on server/client to send and receive data through ports.......
example: Private Sub Form_Load()
Winsock1.LocalPort = 1001
Winsock1.Listen
End Sub
-
Re: COM and TCP
Server Code :
Option Explicit
Private Sub Form_Load()
With Winsock1
.Protocol = sckTCPProtocol
.LocalPort = 2001
.Listen
End With
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim pData As String
Call Winsock1.GetData(pData, vbString, bytesTotal)
Debug.Print pData
End Sub
Client Code :
Option Explicit
Private Sub cmdConnect_Click()
With Winsock2
.Protocol = sckTCPProtocol
.LocalPort = 0
.RemotePort = 2001
.RemoteHost = "localhost"
.Connect
End With
End Sub
Private Sub cmdSendData_Click()
Winsock2.SendData "Hi"
End Sub