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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Server sending & receiving 1

Status
Not open for further replies.

richrock316

Programmer
Jul 30, 2003
57
0
0
US
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.
 
Is the IP address actually the address of the server?
Run CMD & type IPconfig to check.

Have you got windows firewall enabled on either computer? If so disable it.

I know this works using a different port on the server to the client but I've nver tried using the same port.

Try a different port range like 1001 & 1002.
 
The server sets localport, binds, then listens. The client sets remote ip and remoteport, then connects.

To reconnect the client should set localport to 0, which it defaults to, but may as well zero it before every connect. Clients don't listen.

In the ConnectionRequest handler there is no need to check the Winsock state, just close it (stop listening) and then accept the request.
 
Thanks guys.

Once i took out "listen " everything worked fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top