richrock316
Programmer
I am new to writing client-server programs and i am having a problem getting my server program to send as well as receive on one port. I know it is something simple. I even took out all the added stuff my program does to boil it down to the basics to test it. But it still didnt work.
Here is my test code:
Server side:
Private Sub Set_to_Listen_Click()
Winsock1.LocalPort = 8866
Winsock1.Listen
End Sub
Private Sub Send_to_Client_Click()
Dim buffer(0 To 2) As Byte
buffer(0) = 1
buffer(1) = 1
buffer(2) = 1
Winsock1.SendData buffer
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> sckClosed Then
Winsock1.Close
End If
Winsock1.Accept requestID
MsgBox "connected"
End Sub
Client Side:
Private Sub Listen_for_Server_Click()
Winsock1.LocalPort = 8866
Winsock1.Listen
End Sub
Private Sub Establish_Connection_Click()
If Winsock1.State <> sckClosed Then
Winsock1.Close
End If
Winsock1.RemoteHost = "1.2.1.111"
Winsock1.RemotePort = 8866
Winsock1.Connect
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim sData(0 To 2) As Byte
MsgBox "freceived"
Winsock1.GetData sData, vbArray + vbByte '1
End Sub
The server hits the "set_to_listen" button, then the client hits the "establish_connection" button. Once that is done the client hits the "listen_for_server" button and the server sends the data over. At this point i get "Wrong protocol or connection state for the requested transaction or request" error.
I am using 2 computers and if i can get this test working i think i can get my larger program working.
Thanks in advance, i've been pulling my hair out.
Here is my test code:
Server side:
Private Sub Set_to_Listen_Click()
Winsock1.LocalPort = 8866
Winsock1.Listen
End Sub
Private Sub Send_to_Client_Click()
Dim buffer(0 To 2) As Byte
buffer(0) = 1
buffer(1) = 1
buffer(2) = 1
Winsock1.SendData buffer
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> sckClosed Then
Winsock1.Close
End If
Winsock1.Accept requestID
MsgBox "connected"
End Sub
Client Side:
Private Sub Listen_for_Server_Click()
Winsock1.LocalPort = 8866
Winsock1.Listen
End Sub
Private Sub Establish_Connection_Click()
If Winsock1.State <> sckClosed Then
Winsock1.Close
End If
Winsock1.RemoteHost = "1.2.1.111"
Winsock1.RemotePort = 8866
Winsock1.Connect
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim sData(0 To 2) As Byte
MsgBox "freceived"
Winsock1.GetData sData, vbArray + vbByte '1
End Sub
The server hits the "set_to_listen" button, then the client hits the "establish_connection" button. Once that is done the client hits the "listen_for_server" button and the server sends the data over. At this point i get "Wrong protocol or connection state for the requested transaction or request" error.
I am using 2 computers and if i can get this test working i think i can get my larger program working.
Thanks in advance, i've been pulling my hair out.