What is wrong with this code. I am trying to make a simple client-server. Heres the code for the client,and then I will show you the code for the server.
Client:
Private Sub Form_Load()
Dim server As String
Dim Port As String
server = "67.161.136.134"
Port = "5000"
Winsock1.Close
Winsock1.Connect server, Port
End Sub
Private Sub Text1_Change()
Text1.SelStart = Len(Text1.Text) 'scrolls down the text1 box when it needs to
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Form1.Winsock1.SendData Text1.Text & vbCrLf
Text1.Text = Text1.Text & vbNewLine & "You said> " & Text2.Text 'displays what you typed
Text2.Text = "" 'clears the textbox you type in
KeyAscii = 0
End If
End Sub
Private Sub Form_Unload()
Winsock1.Close
End Sub
Server:
Private Sub Command1_Click()
Dim Server As String
Dim Port As String
Winsock1.RemoteHost = IPtxt.Text
Winsock1.RemotePort = Porttxt.Text
Winsock1.Listen
End Sub
Private Sub Command2_Click()
Winsock1.Close
MsgBox ("You have stopped the server.")
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
'this sends data to the client trying to connect
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Accept requestID 'accepts the client connecting
Winsock1.SendData "Connected" 'sends data to the client telling him/her its ok to connect
Label1.Caption = "Status: Connected"
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Winsock1.State = 0 Then End
Winsock1.Close
End Sub
And when I try to run it,it connects in everything,but when I try to type something in Text2,and press enter,I get the error Wrong Protocol or connection state for the requested transaction or request. Please help!
Client:
Private Sub Form_Load()
Dim server As String
Dim Port As String
server = "67.161.136.134"
Port = "5000"
Winsock1.Close
Winsock1.Connect server, Port
End Sub
Private Sub Text1_Change()
Text1.SelStart = Len(Text1.Text) 'scrolls down the text1 box when it needs to
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Form1.Winsock1.SendData Text1.Text & vbCrLf
Text1.Text = Text1.Text & vbNewLine & "You said> " & Text2.Text 'displays what you typed
Text2.Text = "" 'clears the textbox you type in
KeyAscii = 0
End If
End Sub
Private Sub Form_Unload()
Winsock1.Close
End Sub
Server:
Private Sub Command1_Click()
Dim Server As String
Dim Port As String
Winsock1.RemoteHost = IPtxt.Text
Winsock1.RemotePort = Porttxt.Text
Winsock1.Listen
End Sub
Private Sub Command2_Click()
Winsock1.Close
MsgBox ("You have stopped the server.")
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
'this sends data to the client trying to connect
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Accept requestID 'accepts the client connecting
Winsock1.SendData "Connected" 'sends data to the client telling him/her its ok to connect
Label1.Caption = "Status: Connected"
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Winsock1.State = 0 Then End
Winsock1.Close
End Sub
And when I try to run it,it connects in everything,but when I try to type something in Text2,and press enter,I get the error Wrong Protocol or connection state for the requested transaction or request. Please help!