Home > Software engineering >  VB6.0 by use of how to use the winsock 2 network through netcom - outside
VB6.0 by use of how to use the winsock 2 network through netcom - outside

Time:10-09

I use vb6.0 by use of the software, because the company: the company do a computer server, the client devices do in other cities in China, then as long as the equipment to open the software, the company computer can see the client some monitoring data, this is the 2 PC in LAN, and general outside netcom, now do the experiments, were carried out two LAN port mapping, and then the client connect to the server, is first winsock, state=6, connection, 9 later, communication error, the Internet for hours, without the sample, in the same local area network (LAN) can be used, not even the network! Please help! Below is the procedure:
Client:
Private Sub cmdConnect_Click ()
TcpClient. Connect

End Sub

Private Sub Form_Load ()
TcpClient. RemoteHost="XXX. XXX. 7.0.x.x x" server PC with ip138 check the network IP address
TcpClient. RemotePort=5500 set server PC router port mapping
TcpClient. LocalPort=5600 client PC router port mapping set
End Sub

Private Sub tcpClient_DataArrival (ByVal bytesTotal As Long)
Dim strData As String
TcpClient. GetData strData
TexOutput. Text=strData
End Sub

Private Sub Timer1_Timer ()
TexOutput. Text=tcpClient. State
If tcpClient. State=sckError Then MsgBox (" communication error ")
End Sub

Private Sub txtSend_Change ()
TcpClient. SendData publishes the event txtSendData. Text
End Sub

Private Sub wskClient_Error (ByVal Number As an Integer, the Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)

If the Number=10061 Then
MsgBox "please check if the server side open," vbInformation, "Error"
End the If

End Sub

Server:

Private Sub Form_Load ()
TcpServer. LocalPort=5600
TcpServer. Listen
End Sub

Private Sub tcpServer_ConnectionRequest (ByVal requestID As Long)
If tcpServer. State & lt;> SckClosed Then tcpServer. Close
TcpServer. Accept requestID
End Sub

Private Sub tcpServer_DataArrival (ByVal bytesTotal As Long)
Dim strData As String
TcpServer. GetData strData
TxtOutput=strData
End Sub

Private Sub textSendData_Change ()
TcpServer. SendData publishes the event textSendData. Text
End Sub

CodePudding user response:

I don't understand, help me top, for master to see

CodePudding user response:

Private Sub Form_Load ()
TcpClient. RemoteHost="XXX. XXX. 7.0.x.x x" server PC with ip138 check the network IP address
TcpClient. RemotePort=5500 set server PC router port mapping
TcpClient. LocalPort=5600 client PC router port mapping set
End Sub

Server USES port 5600, isn't it, the client can use 5500 to connect

CodePudding user response:

, kao code to write wrong, the server should be 5500, I am a client ends and reset in different local area network (LAN), the two IP do port mapping, is not on,

CodePudding user response:

Why not use VPN devices? That's not a faster connection, or with different speed

CodePudding user response:

The machine address 192.168.127.100,
The router address: 192.168.127.1
The router outside the network address: 192.168.1.147

The router Settings: port 60000 is mapped to a 192.168.127.100

In the machine to do the server, client, also do
Winsock customers begin to connect 192.168.127.1 anyway, think later should use router outside the network address, connection 192.168.1.147, normal, the classmate also normal,
 
Option Explicit

Private Sub Command1_Click ()
Winsock3. Connect "192.168.1.147", 60000,
End Sub

Private Sub Command2_Click ()
Winsock2. SendData publishes the event StrConv (" 123 ", vbUnicode)
End Sub

Private Sub Form_Load ()
For Server LocalPort=60000
Server. Listen
End Sub

Private Sub Server_ConnectionRequest (ByVal requestID As Long)
The Debug. Print Server connection "Request"
Winsock2. Accept requestID
Winsock2. SendData publishes the event StrConv (" is OK. The Server to Connect, "vbUnicode)
End Sub

Private Sub Server_Error (ByVal Number As an Integer, the Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
The Debug. Print "serverListen", Number, Description
End Sub

Private Sub Timer1_Timer ()
Label1. Caption=Server. The State & amp; "" & amp; Winsock2. State & amp; "" & amp; Winsock3. State
End Sub

Private Sub Winsock2_Error (ByVal Number As an Integer, the Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
The Debug. Print "server", Number, Description
End Sub

Private Sub Winsock3_DataArrival (ByVal bytesTotal As Long)
Dim a
Winsock3. GetData a
The Debug. Print a
End Sub

Private Sub Winsock3_Error (ByVal Number As an Integer, the Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
The Debug. Print "Client," Number, the Description
End Sub
  • Related