UDP & Recieve messages

BlitzMax Forums/BlitzMax Programming/UDP & Recieve messages

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

O well,

I've got something working.

Strict

Local socket:TSocket = CreateUDPSocket()
If socket = Null Then RuntimeError "Couldn't create UDP socket"

' Listen to the port!
BindSocket(socket, 8080)

' This isn't required..
' ConnectSocket(socket, HostIp("127.0.0.1"), 8080)

' This seems to be always true..
' If SocketConnected(socket) Then Print "Socket connected."

' Returns 0.0.0.0 : 0
' Print DottedIP(SocketRemoteIP(socket)) + " : " + SocketRemotePort(socket)

Local counter:Int = 0
Local l:Int = 0

While Not KeyDown(key_escape)
	l = SocketReadAvail(socket)
	
	If l
		counter = counter + 1
		Print "Avail: " + l + " bytes."
		Print "Data: " + sRead(socket)
	End If
	
	If counter > 10 Then Exit
Wend

CloseSocket(socket)
End

' ---------------------------------

' This is borrowed from 'Yan'..
Function sRead:String (socket:TSocket)
	Local buf:Byte[1024]
	Local receivedLen = socket.Recv(buf, 1024)
	Return String.FromBytes(buf, receivedLen)
End Function


I borrowed some code from another posting:
BlitzMax Forums/BlitzMax Programming/UDP example

Ghislain