Jump to content

TCP, UDP problem with receiving data


Recommended Posts

I've a problem with receiving data on my PC by TCP and UDP. I can send data to another computer, but can't receive it.

I'm not shure where is the problem (on PC or on "another comupers")

This is client code:

;TCP client
TCPStartup()
$socket = TCPConnect("192.168.0.18", 7777) ;try to connect to server and save number of socket
If $socket = -1 Then ;if $socket = -1 then error
   MsgBox(16, "Error:", "Can't connect to server")
EndIf
$sendedBytes = TCPSend($socket, "nothing here :)") ;send message to connected socket
If $sendedBytes = 0 Then ;if receiving data TCPSend(...) = 0 then error
   MsgBox(16, "Error", "Can't send message")
EndIf
TCPCloseSocket($socket)
TCPShutdown()

and server code:

;TCP server
TCPStartup()
$mainsocket = TCPListen("192.168.0.18", 7777) ;making main receiving socket
While 1 ;receiving loop
   $acceptedSocket = TCPAccept($mainsocket) ;possible connection to accept
   If $acceptedSocket <> -1 Then
      $receivedData = TCPRecv($acceptedSocket, 1024) ;if main socket is connected then receive message
      MsgBox(64, "Received message!", "Message: " & $receivedData)
      TCPCloseSocket($acceptedSocket) ;close open connecion
   EndIf
WEnd
TCPShutdown()

 

When server is on PC I can't receive any messages from any other computers.
When client is on PC I can receive messages on any another computer.

I tried to turn off antiviruses and windows firewall but it did't change anything

 

EDIT:

Error code from client from TCPConnect is 10060 (connection time out) and from TCPSend: 10038

I've found something about 10060 error code, Microsoft says "Connection timed out. A connection attempt failed because the connected party did not properly respond after a period of time, or the established connection failed because the connected host has failed to respond."

So it means that the problem is with time of response but it makes no sense couse "another computer" is Virtual Machine with bridge internet connection from PC (pings beetwen PC  and VM are lower than 1ms.

About 10038 error code microsoft says that this is problem with socket and it actually makes sense.

 
Edited by Turtlix21
Link to comment
Share on other sites

No, they haven't same IP (PC's IP: 0.18 and VM's IP: 0.21), but in both of this codes I have to set up servers IP (in server I'm setting on what ip server will be working, and on client to what server I'm trying to connect).

Edited by Turtlix21
Link to comment
Share on other sites

yep, what I meant was: you said when server is on VM, everything works (so client\server scripts have the right 0.18 IP), but when server is on PC it doesn't work, in this last case, have you kept attention to change accordingly the inserted client\server IPs to 0.21?

Also, it seems stupid but... Server must be started before client execution :P

Edited by j0kky
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...