Sign in to follow this  
Followers 0
Zibit

About UDP

9 posts in this topic

#1 ·  Posted (edited)

hi im trying to send data from 1 PC to the other and cant get it right :S

anyway heres the host's Code

#include <File.au3>
UDPStartup()
;host's IP = 192.168.1.108
;Client's IP = 192.168.1.150
; Register the cleanup function.
OnAutoItExitRegister("Cleanup")
recv()
Func recv()
    $split = 0
    Global $socket2 = UDPBind("192.168.1.108", 27020)
    Do
        $data = UDPRecv($socket2, "27020")
        if $data <> 0 then MsgBox(0, "", $data & " - " & $socket2[2]);<---- here's the problem msgbox doesnt show which means packet doesnt arrive
        if $data <> 0 then $split = StringLeft($data, 1)
        Until $split = 5
        _send()
    EndFunc
; Open a "SOCKET"
;==============================================
Func _send()
$socket = UDPOpen($socket2[2], 27021)
If @error <> 0 Then Exit
$line = _FileCountLines("read.tsf")
$nr = Number($line + 1)
$n = 0
Do
    $n = $n + 1
    $read = FileReadLine("read.tsf", $n)
    Sleep(100)
    $status = UDPSend($socket, $read)
Until $n = $line
UDPSend($socket, "end")
recv()
EndFunc

And heres the Client's script

$socket = UDPOpen("192.168.1.108", 27020)
            $status = UDPSend($socket, "192.168.1.150")
            UDPCloseSocket($socket)
            $i = 0
            $socket = UDPBind("192.168.1.150", 27021)
            while 1
            $i = $i + 1
            $data = UDPRecv($socket, 999999)
            If $data <> "" Then
            $datacalc = StringSplit($data, ",")
            if $datacalc[0] = 2 Then GUICtrlSetData($mylist, $datacalc[2] & "|")
            if $datacalc[1] = 3 then 
                $i = 0
                Do
                    $i = $i + 1
                    $comp = StringCompare(FileReadLine("settings.ini", $i), $datacalc[2] & "," & $datacalc[1], 0)
                Until $comp = 0
                IniWrite("settings.ini", "Servers", FileReadLine("settings.ini", $i), "")
                    EndIf
            if $datacalc[0] = 2 Then IniWrite("settings.ini", "Servers", $datacalc[2], $datacalc[1])
            if $datacalc[0] = 1 Then ExitLoop
            EndIf
        WEnd

Spent days debugging :S! help!

OK just to be clear ! The packet arrives in LAN but it doesnt send from 1 pc to the other :S

Edited by Zibit

Share this post


Link to post
Share on other sites



UDPRecv takes a (numeric) length as second parameter and "27020" is not a number per se. Might be your problem: requesting to receive zero length, then ...

Another question is: why don't you check error conditions after invoking functions that are very likely to fail someday (router reset, cable unplugged, ADSL modem restart, ...)?

Is that spending _days_ debugging? :(


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

This is the same thing as that other thread on UDP thematic on this page.

It's client-server issue. Only one script serves as a server. Not both!

I fail to see how something as simple as that can produce so much issues.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

For some reason you (and some others obviously) have strange urge to bind on client side. Don't do that.

You have socket, don't close it, don't bind. Client doesn't bind. It doesn't work that way.

You are probably confused by the description of the UDPRecv() in the help file. Right?


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

STRAIGHT from the help file:

Client:

;;This is the UDP Client
;;Start the server first

; Start The UDP Services
;==============================================
UDPStartup()

; Register the cleanup function.
OnAutoItExitRegister("Cleanup")

; Open a "SOCKET"
;==============================================
$socket = UDPOpen("127.0.0.1", 65532)
If @error <> 0 Then Exit

$n=0
While 1
 Sleep(2000)
 $n = $n + 1
 $status = UDPSend($socket, "Message #" & $n)
 If $status = 0 then
 MsgBox(0, "ERROR", "Error while sending UDP message: " & @error)
 Exit
 EndIf
WEnd

Func Cleanup()
 UDPCloseSocket($socket)
 UDPShutdown()
EndFunc

Server:

;;This is the UDP Server
;;Start this first

; Start The UDP Services
;==============================================
UDPStartup()

; Register the cleanup function.
OnAutoItExitRegister("Cleanup")

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

While 1
 $data = UDPRecv($socket, 50)
 If $data <> "" Then
 MsgBox(0, "UDP DATA", $data, 1)
 EndIf
 sleep(100)
WEnd

Func Cleanup()
 UDPCloseSocket($socket)
 UDPShutdown()
EndFunc

Experiment with this first.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

yeah... but bind shows the socket where to recv otherwise it would recv randomly or smth, right ?

You were told what's causing issues with your scripts. Also I assume you tried script from the other thread with the same thematic made when this thread.

And now you're posting that. :idea:

edit: I was advised to edit.

Edited by trancexx

♡♡♡

.

eMyvnE

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