Sign in to follow this  
Followers 0
the kick inside

UDP Socket problem

4 posts in this topic

Firstly let me say that although I am an experienced developer I am a relative newby to autoit and to UDP programming....(as I am sure will become patently obvious)

I am trying to throw together (hint this is an excuse for the undocumented code!) a applet to prototype some UDP coms to a hardware terminal (non windows)

The code works just fine in that it opens comms to the terminal, sends it an initialisation string, recieves an acknowlegement, returns the ack to the ack....then when it trys to sendthe next packet it errors to 10049. On investigation the socket variable now has an ip of 0.0.0.0 ???? before this it was at 192.168.0.237 ....

Summary:- the send works, the recieve works, the send works...then the send fails everytime (verified with Ethereal), the recieve STILL works though...and the $outsocket variable displays an IP of 0.0.0.0

Now I know I am doing something stupid, (probably not reallyunderstanding sockets doesnt help!) but i cant see it....and after 2 days hammering my head into the wall I thought I would just ask....

ANY help appreciated:

Heres the code extract (appologies its just a protptype, and i have removed some terminal packet formatting stuff to simplfy...!)

UDPStartup()

If @error <> 0 Then

Exit

EndIf

$outsocket = UDPopen("192.168.0.237",20003)

writetoterm("UA3,100","Y")

GUICtrlSetData($edit_3,$display)

while 1

$data = UDPRecv($outsocket, 999)

if $data<>"" Then

$display=GUICtrlRead($edit_3)&"<"&$data&$crlf

GUICtrlSetData($edit_3,$display)

EndIf

If $data <> "Ue" and $data<>"" Then

writetoterm("UK"&StringRight(stringstripws($data,8),1),"N")

EndIf

$msg = GuiGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

case $msg = $Button_2

Exit

case $msg=$button_7

writetoterm(GUICtrlRead($Input_6),"Y")

case Else

;do nothing

EndSelect

GUICtrlSetData($edit_3,$display)

sleep(10)

WEnd

Func OnAutoItExit()

UDPCloseSocket($outsocket)

UDPShutdown()

EndFunc

Func writetoterm($var,$incflag)

if $incflag="N" Then

$packet=chr(27)&$var

Else

$packet=chr(27)&$var&$nextflag

endif

$status = UDPSend($insocket,$packet)

$display=GUICtrlRead($edit_3)&">"&$packet

$nextflag=$nextflag+1

if $nextflag>9 then $nextflag=0

GUICtrlSetData($edit_3,$display)

EndFunc

Share this post


Link to post
Share on other sites



Use the autoit tags to formate your code (the A in the middle of the editor).

Try to provide a sample using the helpfile code for UDPRecv and UDPSend that will fail the way you have described in your first post.

Share this post


Link to post
Share on other sites

Use the autoit tags to formate your code (the A in the middle of the editor).

Try to provide a sample using the helpfile code for UDPRecv and UDPSend that will fail the way you have described in your first post.

OK thanks for the hint i will try the autoit tags, unfortuantely the help code doesnt appear to be trying to do wehat i am trying to do...i.e establish bi-directlional communications with a device with a fixed ip and port....

I will give it another go and see how i get on, what i dont get is why it works then returns 0.0.0.0 for the IP, that indictes taht the ARP table is up the creek, buti t isnt and other VB based software talks tothe hardware just fine....bit ofa head scratcher...

Share this post


Link to post
Share on other sites

Finally worked it out, I was presuming iI was doing something wrong - I normally am!

I finally thought 'well give ita go' and pressed the update button on autoit and foundi was one release back, the new release cured it!

thanks for the help and support anyway

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