Sign in to follow this  
Followers 0
Hooch

IP of incoming communication over UDP ?

15 posts in this topic

I am playing with a UDP example from the forums, had to modify it and install the latest beta but I got it working ;)

Anyways, on the server side, I don't have access to the incoming connections meta data, i.e. the connection IP address. This info would be needed to be able to block IP addresses etc. I know the information is in the packet but that info is not exposed in the functions that are currently available.

Am I missing something obvious?

Share this post


Link to post
Share on other sites



Heh thanks for the reply Larry, now can you talk to me like I'm stupid please ;)

What API....

Share this post


Link to post
Share on other sites

Ok I gave that a try Larry,

Server:

#include <vars.au3>
#include <functions.au3>
#include <gui.au3>

HotKeySet("{F10}", "Quit")
UDPStartup()
$uServer = UDPBind(@IPAddress1, 31337)
If $uServer = -1 Then Exit

;

While 1
    $uText = UDPRecv($uServer, 100)
    If $uText <> "" Then
        $cIP = SOCKET2IP($uServer)
        MsgBox(0, "IP Address", "client IP: " & $cIP)
    EndIf
WEnd

Client:

UDPStartup()
$uClient = UDPOpen("192.197.4.75", 31337)
If $uClient = -1 Then Exit

;

While 1 
    $uStatus = UDPSend($uClient, $PublicIP & ": Hello")
    sleep(1)
WEnd

All I am getting is "0" so most likely I am doing something wrong...

Share this post


Link to post
Share on other sites

I tried it with the UNBIND socket and also on the UDPRecv... same result... I take it that it worked for you Larry, are you able to post the code you tested it with?

Share this post


Link to post
Share on other sites

ahh....

Share this post


Link to post
Share on other sites

I may not be understanding you correctly, but from the beta helpfile, can't you just use the return of UDPBind?

$array[2] = IP Address

-Livewire

Share this post


Link to post
Share on other sites

I may not be understanding you correctly, but from the beta helpfile, can't you just use the return of UDPBind?

$array[2] = IP Address

-Livewire

Livewire, you're right, the UDP "socket" (which is an array) contains all the information of the connection. That was necessary to get the UDP stuff to work.

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

Isn't that the IP of the socket you have bound to as the server? What I need is the IP of the incoming connections to the server, not the server itself.

Share this post


Link to post
Share on other sites

No...it's the IP of the incomming communication...at least I just tried it and it is...try it.

-Livewire

Send some data to this...

UDPStartup()

$socket = UDPBind(@IPAddress1, 20000) ; Change port if u want

If @error <> 0 Then Exit

While 1

$data = UDPRecv($socket, 5000)

If $data <> "" Then

MsgBox(0,"Testing","$socket[1] = " & $socket[1] & @CRLF & _

"$socket[2] = " & $socket[2] & @CRLF & _

"$socket[3] = " & $socket[3] & @CRLF)

EndIf

sleep(100)

WEnd

Func OnAutoItExit()

UDPCloseSocket($socket)

UDPShutdown()

EndFunc

Share this post


Link to post
Share on other sites

Oh well sheesh... ok cool I'll give that a go.

One thing I wonder about is multiple connections.

I am planning a tool that 1-10 clients will be sending a command as well as periodic keep-alive broadcasts to the server and I wanted to tag each incoming cumunication with it's ip and timestamp from the server side.

So... the value of $array[2] = IP Address will be the data about the communication that is currently being processed? I overlooked that as the Ubind is setup prior to our runtime loop so I expected that to be static data from that point.... am I making sense?

Share this post


Link to post
Share on other sites

My version of the help file doesn't contain a UDPAccept function....

Share this post


Link to post
Share on other sites

That example is modified from the beta helpfile.

After you receive data (UDPRecv), I'm assuming $array[2] becomes the IP of the computer that that specific packet came from.

-Livewire

Share this post


Link to post
Share on other sites

Ok cool then, if that's how it works I am good to go. I'll report back how I make out ;)

Ah that is indeed how it works. Nice. Thank you for the info and the replies people :P

Share this post


Link to post
Share on other sites

No prob...I use UDP also...it's good info to know.

-Livewire

Share this post


Link to post
Share on other sites

Isn't that the IP of the socket you have bound to as the server? What I need is the IP of the incoming connections to the server, not the server itself.

After a UDPRecv() it's the data of the connecting host.

Cheers

Kurt

What IS an incoming connection for this UDP? I see a "main" socket set using UDPBind() and then just UDPRecv()... I don't see any UDPAccept() that would give you a socket for parsing.

LAr.

Actually there is no UDPAccept() because there are no "connections" like in TCP. UDPRecv() will just return the incoming data of the last client that sent something. Additionally UDPRecv() it sets the IP addr and port of the incoming "connection", so you can answer to that client. I could not find another way to do it, as there are no established connections for UDP.

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