Jump to content

IP of incoming communication over UDP ?


Hooch
 Share

Recommended Posts

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?

Link to comment
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...

Link to comment
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 *

Link to comment
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

Link to comment
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?

Link to comment
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 *

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...