UDP - Tutorial/Manual, anyone ?

Posted by Alca on Wed 18 Jun 2008 09:23 PM — 4 posts, 18,307 views.

#0
Oki, not sure if this belongs here, but here goes anyway...

I've been toying around with Nick's Status Bar thingy, and I love it. I love it so much, that I want to be able to code stuff like this myself.

Now, the only coding language I have some experience with is Python.

My questions:

1) Is it possible to write a comparable program in Python ?
2) If it is, could someone link me to a decent UDP manual/tutorial ?

My 'ultimate' goal would be to have a frame with buttons that would send messages to MUSHclient. Since MUSH comes with UdpListen, I only need to implement a way to send packages using my program.


Any help or advice is most welcome ! Also, if anyone would think this is infeasible or too hard to accomplish, speak up. I already waste enough of my time on games ^^
Australia Forum Administrator #1
I had forgotten about UdpListen. :)

I don't know enough Python to answer your question, sorry, but I can demonstrate how to handle the UDP packets at the MUSHclient end.

The small plugin below shows how to use UdpListen. You need to specify an address to listen to (or 0.0.0.0 for all addresses), and a port to listen to. Finally you specify the name of a script in your plugin. The script will receive any UDP packets addressed to that port.



<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Thursday, June 19, 2008, 8:29 AM -->
<!-- MuClient version 4.27 -->

<!-- Plugin "UDPlisten_demo" generated by Plugin Wizard -->

<muclient>
<plugin
   name="UDPlisten_demo"
   author="Nick Gammon"
   id="2d536fbbcfe2aed9d8872aec"
   language="Lua"
   purpose="Shows how to use UdpListen"
   date_written="2008-06-19 08:27:07"
   requires="4.00"
   version="1.0"
   >

</plugin>

<!--  Script  -->

<script>
<![CDATA[
function listener (s)
  ColourNote ("white", "blue", "Got UDP packet: " .. s)
end -- listener 

require "check"
check (UdpListen ("0.0.0.0", 4112, "listener"))
]]>
</script>

</muclient>



To test it I used UDPSend:


/UdpSend ("127.0.0.1", 4112, "Hi there")  --> Got UDP packet: Hi there
Amended on Wed 18 Jun 2008 10:38 PM by Nick Gammon
Netherlands #2
Python can easily do what you want it to do. I hope I'm understanding right that you want to have the entire graphical application be written in Python, otherwise please ignore this post. :)

wxPython is a Pythonwrapper for an often-used graphical toolkit known as wxWidgets. It's fast and supported on many different platforms. Alternatively, you could use TK (or was it TCL that does GUIs? I forgot!) which comes with Python, but it isn't pretty and considered to be outdated for as far frameworks go (or so I've read). Link: http://www.wxpython.org/

For as far using UDP in Python goes... there's the socket module for that. It's supported on pretty much every platform, too. You can find a very comprehensive manual at (1). However, that manual is a bit too general and extensive and doesn't go into the details about udp. You can find more examples at (2).


(1) - http://docs.python.org/dev/library/socket.html?highlight=udp
(2) - http://www.evolt.org/article/Socket_Programming_in_Python/17/60276/


Good luck, and please ask more questions as they arise. :)
Amended on Thu 19 Jun 2008 05:40 AM by Worstje
#3
Yes, I do want my program to be written solely in Python.
Already got wxPython (way more user-friendly), been making my own doodles and hangman games for Python practice for some time now, so I think I grasp the basics about making decent frames.

I didn't know there was a module for stuff like this in Python... Should've known though, it's got modules for everything.

You two answered my questions prefectly really ^^ From here, I'll try to get things working, and I'll let you know should I succeed.

Thanks for the answers, the links, and the plugin!