Jump to content
Sign in to follow this  
yucatan

how to talk from udp server to udp client.

Recommended Posts

yucatan

Hello

i'm building an udp server with an udp client but i seems i cant get it working to send a message from the udp server to the udp client

Anyone any help?

client:

UDPStartup()
;188.165.40.108:29022
$socket = udpopen("127.0.0.1", 65532)
If @error <> 0 Then
    ConsoleWrite(@error)
    Exit
EndIf



;$cdkey = $argv[3]
;$cdkeypart = substr($cdkey, 0, 16)
;$pbguid = "123456789abcdef1234567890abcdefa"


;ÿÿÿÿgetKeyAuthorize 0 XHU6E7666HHJPAP3 PB 123456789abcdef1234567890abcdefa     WL3ZW7QJXJA3P3GE8DE3
$data = ""
$auth =   udpsend($master, "ÿÿÿÿgetKeyAuthorize 0 P7XLP5EH6A5HJL7L PB 123456789abcdef1234567890abcdefa")
$status = udpSend($socket, 'ÿÿÿÿgetchallenge 0')
While 1
$data = udpRecv($socket, 99999)
if $data <> "" Then
           ConsoleWrite($data & @CRLF)
        exitloop
   EndIf
WEnd

$challange = StringMid($data, 22, 20)
ConsoleWrite($challange&@LF)


$challange = StringReplace($challange, " ", "")
ConsoleWrite($challange&@lf)

UDPSend($socket, "ÿÿÿÿconnect \cg_predictItems\1\cl_anonymous\0\cl_punkbuster\1\cl_voice\1\cl_wwwDownload\1\rate\25000\snaps\20\name\yorickispro\protocol\118\challenge\"&$challange&"\qport\30336")
;ÿÿÿÿconnect "\cg_predictItems\1\cl_anonymous\0\cl_punkbuster\1\cl_voice\1\cl_wwwDownload\1\rate\25000\snaps\20\name\FMNZRIMY\protocol\118\challenge\-1350344700\qport\30336"

While 1
$data = udpRecv($socket, 99999)
if $data <> "" Then
           ConsoleWrite($data & @CRLF)
        ;exitloop
   EndIf
WEnd


;ConsoleWrite($teller & @CRLF)
;until $henk=0

server:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <Array.au3>
UDPStartup()
OnAutoItExitRegister("Cleanup")

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

Local $file, $btn, $msg, $myedit, $msg


       GUICreate("My GUI edit",700,700) ; will create a dialog box that when displayed is centered
$file = GUICtrlCreateInput("", 10, 650, 300, 20)
$myedit = GUICtrlCreateEdit("" & @CRLF, 0, 0, 600, 600, $ES_AUTOVSCROLL + $WS_VSCROLL)
$handle = GUICtrlGetHandle ( $myedit )


GUICtrlSetData($myedit, "UDP server started"&@crlf,"1")
    GUISetState()
    ; Run the GUI until the dialog is closed
    While 1
        $data = ""
        $msg = GUIGetMsg()
         If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        Local $data = UDPRecv($socket, 99999)
            If $data <> "" Then UDPSend($socket[1], "ÿÿÿÿchallengeResponse 1425526264")

            GUICtrlSetData($myedit, $data &@crlf,"1")





WEnd
        GUIDelete()
        exit









While 1

WEnd
sleep (100)



$data = ""
While 1

    Local $data = UDPRecv($socket, 99999)
    If $data <> "" Then
        ConsoleWrite($data & @LF)
    EndIf
    Sleep(100)
WEnd




Func Cleanup()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc   ;==>Cleanup

Share this post


Link to post
Share on other sites
water

Have a look at the example code in UDPRecv and UDPSend. Combine both and you have an UDP client/server application.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
yucatan

water i did take a look in the help filed but the help files only explaine how the client can send to the server that part i got working but i'm unable to use that same socket to send data from the server towards the client

Share this post


Link to post
Share on other sites
water

If you send data from A to B then A is the client and B the server. If you then want to send some data back from B to A then A needs to be the server.

Which means you need to run client and server on A and B.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
yucatan

Water is this only with autoit applications or is this just the UDP protocol?

because for example call of duty uses udp to communicate between client een server but ofcrouse people that play call of duty dont have port forwarding.

but still a call of duty server is able to send data towards call of duty players. and i'm sure this is done by udp

do you maby have an explaination for that?

Share this post


Link to post
Share on other sites
water

Looks like your already has both functions implemented (send and receive).

If it is not working you need to add some debugging code (MsgBox etc.).


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
yucatan

i think i already found the problem i'm sending towards an socket but thats not working in UDP i think i should be sending toward ip:port gonna check it out tomorrow

Kind regards

Share this post


Link to post
Share on other sites
water

I don't understand. A socket address is the IP address plus port number. So this aren't two different things.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
yucatan

the problem i'm having is that when i from the server send data towards the socket then the server recieves its own sended data instead of it has been sended towards the client

Share this post


Link to post
Share on other sites
water

Looks like the IP used for sending the data is wrong.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
yucatan

water how exacly do you mean ? you mean the

UDPSend($socket[1], "ÿÿÿÿchallengeResponse 1425526264") in the server?

Share this post


Link to post
Share on other sites
water

If a message you send from the server to the client  is being read from the server then you either

  • send the message to the wrong ip:port
  • ip:port is correct but the message is forwarded by the client to the sender

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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  

×