﻿id	summary	reporter	owner	description	type	status	milestone	component	version	severity	resolution	keywords	cc
1869	Specify UDP Source Port	anonymous		"Discussion here is here, start reading at post 12:
http://www.autoitscript.com/forum/topic/124405-udp-server-talk-to-client/

--

The server's source port in a reply message is random and does not match the servers listen port.

example with current procedures:
1. server opens on port 251
2. client sends message to server with destination port 251, source port 1234(random but ok)
3. server sends reply. destination port 1234, source port 5678(random NOT ok)

How it should be:
1. server opens on port 251
2. client sends message to server with destination port 251, source port 1234(random but ok)
3. server sends reply. destination port 1234, source port 251(not random, same as server port, good!)

To fix this, I suggest UDPOpen() should have an optional parameter to specify source port instead of always using a random port. 

As discussed, It is not currently possible to make a UDP DNS server that compiles to RFC specifications. The server should reply to client messages with the servers listen port as it's source port.


{{{
;;This is the UDP Server
;;Start this first

#Include <Array.au3>
HotKeySet(""{ESC}"", ""quit"")

; Start The UDP Services
;==============================================
UDPStartup()

; Register the cleanup function.
OnAutoItExitRegister(""Cleanup"")

; Bind to a SOCKET
;==============================================
$Socket = UDPBind(""192.168.1.11"", 251)

While 1
    ;get UDP data from client
    $Data = UDPRecv($Socket, 50,3)
    
    If IsArray($Data) Then
        ConsoleWrite($Data[0])
        ConsoleWrite(@CRLF)
        
        ;create temp socket from incomming IP/PORT
>>> I should be able to specify a source port with UDPOpen that is the same as the listen port of UDPBind().
        $SocketIn = UDPOpen($Data[1], $Data[2])
        
        ;send a reply message
        ConsoleWrite(""Sending reply: Hello Client!"")
        $status = UDPSend($SocketIn, ""Hello Client!     "") 
        If $status = 0 then
            MsgBox(0, ""ERROR"", ""Error while sending UDP message: "" & @error)
            Exit
        EndIf
        
        ;remove temp socket
        UDPCloseSocket($SocketIn)
        $Data[0] = 0
        
        ConsoleWrite(@CRLF)
        ConsoleWrite(@CRLF)
    EndIf
    sleep(100)
WEnd

Func quit()
    UDPCloseSocket($Socket)
    UDPShutdown()
    exit
EndFunc
}}}


Matt."	Feature Request	closed		AutoIt		None	Rejected		
