Sign in to follow this  
Followers 0
Rad

UDPBind 'sockets'

3 posts in this topic

My goal is pretty simple, I want to send some messeges to all connections on my UDP server. The only problem is... the only connection i can see is $socket.

I dont really see how this works, in the example does UDPBind() only take one connection? If thats the case, how do I know when its connected? I need some help

UDPStartup()

; Bind to a SOCKET
;==============================================
$socket = UDPBind("127.0.0.1", 65532)
If @error <> 0 Then Exit

While 1
    $data = UDPRecv($socket, 50)
    If $data <> "" Then
        msgbox(0,"",$socket)
        MsgBox(0, "UDP DATA", $data, 1)
    EndIf
    sleep(100)
WEnd

Func OnAutoItExit()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

My goal is pretty simple, I want to send some messeges to all connections on my UDP server. The only problem is... the only connection i can see is $socket.

When you UDPRecv() data from a client the socket data is updated with the client information (ip, port, etc.). So, just use that socket to answer the client. There is no way to send data to all "connected" clients as there are NO established connections with UDP. UDP is a connectionless protocoll, so you'll never know if the client is still there to receive data. That's how UDP works and there is nothing you can do about it, except using TCP instead of UDP.

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

When data comes in... create an array of client info... check the info against the info stroed to see if you already know this client... if not, add the info... then when you send... send to all in your "info array"

Lar.

It's still not possible to know if a client is still there to receive the data. If things go wrong, you'll end up sending data to a totally unrelated system if the IP address has been reassigned by the ISP. The only way would be to implement a kind of keep-alive between client and server, to inform the server, that the client is still there and to update the ip address in case of a reassignment.

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
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
Sign in to follow this  
Followers 0