Hi,
i have some problems with my UDP Transfer. My Server don't get a correct String. The Integers are just fine. It seems to be a Misstake at the Byte Pointers or so ...
Maybe anyone see my Misstake:
Server:
Client:
I'm very thankful for some hints :-)
i have some problems with my UDP Transfer. My Server don't get a correct String. The Integers are just fine. It seems to be a Misstake at the Byte Pointers or so ...
Maybe anyone see my Misstake:
Server:
SuperStrict ' Create a UDP Socket Local client:TSocket = CreateUDPSocket() ' Bind to Port for incomming Messages If Not BindSocket(client, 8085) Then RuntimeError( "Unable to listen on port." ) ' tmp Buffer - the Bytes that i got from UDP Socket Local tmp:Byte Ptr[1024] ' The Variables (from client) Local name:String Local xpos:Int Local ypos:Int ' Read all incomming messages While True If SocketReadAvail(client) Then ' print how many bytes arrived Local avail:Int = client.recv(tmp, 1024) Print (String(avail) + " Bytes available.") ' first integer Print ("Name has "+String(Int(tmp[0]))+" Bytes") ' second is my name string name.FromBytes(tmp[1], Int(tmp[0])) Print(name) ' my location variables xpos = Int(tmp[2]) ypos = Int(tmp[3]) Print "got packet with: "+name+" xpos: "+String(xpos)+" ypos: "+String(ypos) Else Delay(500) EndIf Wend CloseSocket(client) End
Client:
SuperStrict ' Create a UDP Socket Local server:TSocket = CreateUDPSocket() ' Bind Socket to a Port (incomming Messages) If Not BindSocket(server, 8086) Then RuntimeError("Unable to Bind Socket - Port 8086 maybe in use...") ' Connect to a IP and Port (outgoing Messages) If Not ConnectSocket(server, HostIp("127.0.0.1"), 8085) Then RuntimeError "Couldn't connect to server" ' Player Name + x position + y position Local name:String = "Player" Local xpos:Int = 450 Local ypos:Int = 400 ' Create Data Ptr to be send Local data:Byte Ptr[4] data[0] = Byte Ptr(name.length) data[1] = Byte Ptr(name.ToCString()) data[2] = Byte Ptr(xpos) data[3] = Byte Ptr(ypos) ' send data (int + string + int + int) / int = 4 byte server.send(data, 4 + name.length + 4 + 4) CloseSocket(server) End
I'm very thankful for some hints :-)