UDP connection... sucessful?
Monkey Forums/Monkey Beginners/UDP connection... sucessful?
| ||
_socket = New Socket("datagram") _socket.ConnectAsync("localhost",41337,self) and I have all methods implemented in my app as well Method OnConnectComplete:Void( connected:Bool,source:Socket ) If Not connected Error "Connection error" Else Print "Connection established!" End Method Thats a "CLIENT" code, and when I execute it. it connects to me sucessfully, EVEN though I DID not launch my "SERVER" executable. That means it did NOT BIND a socket that would act as a "server" and listen to a port But it still says "Connection established" Is that the way it is supposed to be? ) Do I miss something? |
| ||
Here is the whole thing:Import mojo Import brl.socket '══════════════════════════════════════════════════════════════════════════════════════ ' Class MyApp Extends App Implements IOnConnectComplete, IOnSendComplete Field _socket:Socket Field _port:= 41337 Field _data:= New DataBuffer(1024) Field _address:SocketAddress Method OnCreate:Int() _socket = New Socket("datagram") _socket.ConnectAsync("localhost",_port,self) _data.PokeString(0,"SendThisText") SetUpdateRate(60) Return 0 End Method OnUpdate:Int() UpdateAsyncEvents() If KeyHit(KEY_SPACE) Then _socket.SendAsync _data,0,_data.Length,Self Return 0 End Method OnRender:Int() Return 0 End '══════════════════════════════════════════════════════════════════════════════════════ ' Method OnConnectComplete:Void( connected:Bool,source:Socket ) If Not connected Error "Connection failed" Else Print "Connection sucessful!" End Method Method OnSendComplete:Void( data:DataBuffer,offset:Int,count:Int,source:Socket ) Print "Send complete" End Method End Class '══════════════════════════════════════════════════════════════════════════════════════ ' Function Main:Int() ; New MyApp() ; Return 0 ; End Function |
| ||
https://en.wikipedia.org/wiki/User_Datagram_Protocol UDP is a message-based connectionless protocol. Hm... Brl.Socket doesn't allow to send UDP packets without connection to a remote server. It's a bug IMHO. |
| ||
It could be a bug, or it's just something simple that's missing( I've been looking into echoserver_udp example and found this: If I don't create server, then client connection will fail. However if I strip the example of ALL server related code then it will be the same as with me now (it would say that connection has been established) |
| ||
Still no luck wrapping my head around it.( Any clues? |