Home > Software engineering >  Seek help from a great god, VB network programming operation to winsock. Connect error 40020
Seek help from a great god, VB network programming operation to winsock. Connect error 40020

Time:10-02

The most simple VB network programming, the first step is to write failure, self-confidence is hit... Run to the winsock. Connect error 40020, post my code below
Server:
Private Sub Command1_Click ()
End
End Sub

Private Sub Form_Load ()
Textsend. Visible=False
Textget. Visible=False
Winsockserver. LocalPort=8888
Winsockserver. Listen
End Sub

Private Sub textsend_Change ()
Winsockserver. SendData publishes the event textsend. Text
End Sub

Private Sub Winsockserver_Close ()
Winsockserver. Close
End
End Sub


Private Sub Winsockserver_ConnectionRequest (ByVal requestID As Long)
Textsend. Visible=True
Textget. Visible=True
If Winsockserver. State & lt;> SckClosed Then Winsockserver. Close
Winsockserver. Accept requestID
End Sub


Private Sub Winsockserver_DataArrival (ByVal bytesTotal As Long)
Dim TMPSTR As String
Winsockserver. GetData TMPSTR
Textget. Text=TMPSTR
End Sub


Client:
Private Sub Command1_Click ()
End
End Sub


Private Sub Command2_Click ()
Winsockclient. Connect
End Sub

Private Sub Form_Load ()
Textsend. Visible=False
Textget. Visible=False
Winsockclient. RemotePort=1001
Winsockclient. RemoteHost="SCCDSZ"
End Sub


Private Sub Text1_Change ()
Winsockclient. RemoteHost=Text1. Text
End Sub


Private Sub textsend_Change ()
Winsockclient. SendData publishes the event textsend. Text
End Sub

Private Sub Winsockclient_Close ()
Winsockclient. Close
End
End Sub

Private Sub winsockclient_Connect ()
Textsend. Visible=True
Textget. Visible=True
Command2. Visible=False
End Sub


Private Sub winsockclient_DataArrival (ByVal bytesTotal As Long)
Dim TMPSTR As String
Winsockclient. GetData TMPSTR
Textget. Text=TMPSTR
End Sub

CodePudding user response:

You this is TCP or udp

CodePudding user response:

1. Make sure your server and the client are TCP protocol,
2. The client's remote port is 1001, server is listening on port 8888
3. Now you this program at run time, the new connection client will top off the old client

CodePudding user response:

Winsockclient. RemotePort should be assigned a value of 8888, Winsockclient. RemoteHost IP address with the server end,
  • Related