Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

about winsock in vb

Status
Not open for further replies.

horoscope

Technical User
Dec 1, 2002
17
CN
the program below can not work.
why ,and how to set a port number in win2000.
thanks.
server:
Private Sub Form_Load()
SockServer.LocalPort = 2000
SockServer.Listen
End Sub
Private Sub Form_Unload(Cancel As Integer)
SockServer.Close
End Sub
Private Sub SockServer_Close()
SockServer.Close
End Sub
Private Sub SockServer_ConnectionRequest(ByVal requestID As Long)
SockServer.Close
SockServer.Accept requestID
End Sub
Private Sub SockServer_Data
Arrival(ByVal bytesTotal As Long)
Dim s As String
SockServer.GetData s
Text1.Text = s
End Sub
Private Sub Command1_Click()
SockServer .SendData Text2.Text
End Sub

client:

Private Sub Form_Load()
SockCl.RemoteHost ="127.0.0.1?
SockCl.RemotePort = 2000
SockCl.Connect

End Sub
Private Sub Form_Unload(Cancel As Integer)
SockCl.Close
End Sub
Private Sub SockCl_Close()
SockCl.Close
End Sub
Private Sub SockCl_DataArrival(ByVal bytesTotal As Long)
Dim s As String
SockCl.GetData s
Text1.Text = s
End Sub
Private Sub Command1_Click()
SockCl.SendData Text2.Text
End Sub

 
For a simple server/client program running on the same maschine it works, note the client code;

SockCl.RemoteHost = SockCl.LocalIP

The server form must be started first so that the client has something to connect to. Running on separate maschines the server must be started first and SockCl.RemoteHost = the server IP adresse.

Code:
[Green]'server:[/Green]

[Blue]Private Sub Form_Load()[/Blue]
SockServer.LocalPort = 2000
SockServer.Listen
[Blue]End Sub[/Blue]

[Blue]Private Sub Form_Unload(Cancel As Integer)[/Blue]
SockServer.Close
[Blue]End Sub[/Blue]

[Blue]Private Sub SockServer_Close()[/Blue]
SockServer.Close
[Blue]End Sub[/Blue]

[Blue]Private Sub SockServer_ConnectionRequest(ByVal requestID As Long)[/Blue]
SockServer.Close
SockServer.Accept requestID
[Blue]End Sub[/Blue]

[Blue]Private Sub SockServer_DataArrival(ByVal bytesTotal As Long)
Dim s As String[/Blue]
SockServer.GetData s
Text1.Text = s
[Blue]End Sub[/Blue]

[Blue]Private Sub Command1_Click()[/Blue]
SockServer.SendData Text2.Text
[Blue]End Sub[/Blue]

Code:
[Green]'client:[/Green]

[Blue]Private Sub Form_Load()[/Blue]
SockCl.RemoteHost = SockCl.LocalIP
SockCl.RemotePort = 2000
SockCl.Connect
[Blue]End Sub[/Blue]

[Blue]Private Sub Form_Unload(Cancel As Integer)[/Blue]
SockCl.Close
[Blue]End Sub[/Blue]

[Blue]Private Sub SockCl_Close()[/Blue]
SockCl.Close
[Blue]End Sub[/Blue]

[Blue]Private Sub SockCl_DataArrival(ByVal bytesTotal As Long)
Dim s As String[/Blue]
SockCl.GetData s
Text1.Text = s
[Blue]End Sub[/Blue]

[Blue]Private Sub Command1_Click()[/Blue]
SockCl.SendData Text2.Text
[Blue]End Sub[/Blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top