Sign in to follow this  
Followers 0
KenanDeHart

Sending a variable over a UDP connection

3 posts in this topic

I am unable to send a variable over a UDP connection. Please excuse my poor english. (For full story, read spoiler)

Hello, I am attempting to create a program that will allow me to do simple things with my friends computer at school. His computer is right next to mine, and since we work on projects together, we continually need to show each other pieces of code, websites, cmd commands, etc....

My plan is to create a UDP connection in which the "server" is on his computer and the "client" is on mine. I am 100% new to autoit, so I have been consistently having basic issues. While I have been able to figure most of them out on my own, I can't solve this one simple problem.

I am trying to make an option for me to see all of the running processes on his computer. I am first trying to get the total number of processes running on his computer so I can make an array, I am able to find the total number of processes, but when I try to send that number, I seem to receive some sort of memory address on my side. Look at the code below please

Here is where I am having a problem.

On the server side:

$list = ProcessList()
For $i = 1 To $list[0][0]
$totalproc = $totalproc + 1
Next
$n=1
UDPSend($sendsocket, $totalproc)

On the client side:

While $Procreq = ""
local $Procreq = UDPRecv($recvsocket, 1000000)
If $Procreq <> "" Then
     MsgBox(1,"",$Procreq)
EndIf
Sleep(100)
WEnd

The message box displays the following value for $procreq

"0x36000000"

This kind of looks to me like a memory address, but I am not sure.

If you have any questions, or need further explanation, let me know.

Share this post


Link to post
Share on other sites



Here is a full source of both the client and of the server, in case it will be useful.

SERVER

#include <Process.au3>
UDPStartup()
$totalproc = 0
; Register the cleanup function.
OnAutoItExitRegister("Cleanup")
; Bind to a SOCKET
;==============================================
Global $recvsocket = UDPBind(@IPAddress1, 65532)
If @error <> 0 Then Exit
Global $sendsocket = UDPOpen(@IPAddress1, 65531)
If @error <> 0 Then Exit
While 1
$Proccheck = "0"
    Local $data = UDPRecv($recvsocket, 50, 2)
    If $data <> "" Then
  MsgBox(1,"",$data[0])
  If $data[0] = "PR" Then
   MsgBox(1,"","Server received process list request")
   $list = ProcessList()
   For $i = 1 To $list[0][0]
    $totalproc = $totalproc + 1
   Next
   $n=1
   UDPSend($sendsocket, $totalproc)
   $data = ""
   $Proccheck = "1"
  EndIf
  If $Proccheck = "0" Then
   _RunDos($data[0])
  EndIf
    EndIf
    Sleep(100)
WEnd
Func Cleanup()
    UDPCloseSocket($recvsocket)
UDPCloseSocket($sendsocket)
    UDPShutdown()
EndFunc   ;==>Cleanup

CLIENT

#include <Process.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

Local $Procreq = ""
UDPStartup()
Global $sendsocket = UDPOpen(@IPAddress1, 65532)
If @error <> 0 Then Exit
Global $recvsocket = UDPBind(@IPAddress1, 65531)
If @error <> 0 Then Exit


$ClientGUI = GUICreate("Control Panel", 615, 306, 192, 124)
;notepad section
$notepad = GUICtrlCreateButton("Start notepad", 24, 16, 129, 41)
$notepadstream = GUICtrlCreateButton("Begin text streaming", 160, 16, 129, 41)
$notepadinput = GUICtrlCreateInput("", 296, 24, 313, 21)
;Opening a URL
$url = GUICtrlCreateButton("Open this URL ->", 24, 80, 131, 41)
$urlinput = GUICtrlCreateInput("", 160, 88, 201, 21)
;View / Kill processes
$procmang = GUICtrlCreateButton("Open process manager", 24, 144, 131, 41)
;Run a CMD command
$customcmd = GUICtrlCreateButton("Run a CMD command", 24, 208, 129, 41)
$cmdinput = GUICtrlCreateInput("", 160, 216, 201, 21)
;For a later use
$Button2 = GUICtrlCreateButton("Empty", 438, 80, 131, 41)
$Button3 = GUICtrlCreateButton("Empty", 440, 150, 131, 41)
$Button4 = GUICtrlCreateButton("Empty", 437, 212, 129, 41)
GUISetState(@SW_SHOW)

While 1
$Proclist = ""
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $notepad
   Local $status = UDPSend($sendsocket, "start notepad")
   If $status = 0 Then
    MsgBox(0, "ERROR", "Error while sending UDP message: " & @error)
    Exit
   EndIf
  Case $url
   Local $status = UDPSend($sendsocket, "start " & GUICtrlRead($urlinput))
   If $status = 0 Then
    MsgBox(0, "ERROR", "Error while sending UDP message: " & @error)
    Exit
   EndIf
  Case $customcmd
   Local $status = UDPSend($sendsocket, GUICtrlRead($cmdinput))
   If $status = 0 Then
    MsgBox(0, "ERROR", "Error while sending UDP message: " & @error)
    Exit
   EndIf
  Case $procmang
   Local $status = UDPSend($sendsocket, "PR")
   If $status = 0 Then
    MsgBox(0, "ERROR", "Error while sending UDP message: " & @error)
    Exit
   EndIf
   While $Procreq = ""
    local $Procreq = UDPRecv($recvsocket, 1000000)
    If $Procreq <> "" Then
     MsgBox(1,"",$Procreq)
    EndIf
    Sleep(100)
   WEnd

EndSwitch
WEnd
Func Cleanup()
UDPCloseSocket($recvsocket)
UDPCloseSocket($sendsocket)
UDPShutdown()
EndFunc   ;==>Cleanup

Share this post


Link to post
Share on other sites

Sorry guys, just realized that is hexadecimal. Lol.

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