I'm trying to learn about udp and most of the examples I am looking at are a little complex. Can someone please show a link or paste some code for a 'hello world' sort of server-side-UDP script?
I'm trying to learn about udp and most of the examples I am looking at are a little complex. Can someone please show a link or paste some code for a 'hello world' sort of server-side-UDP script?
All the network programming I've done is tcp, but AFAIK udp is pretty similar as far as the basic arrangement is concerned, except you do not connect() accept() or listen(). Can you set up and use an inet socket?
If you're on linux, the GNU C ref manual has a fairly down to earth section on sockets including UDP (aka "datagrams"), google "16.10.3 Datagram Socket Example" and you'll find it.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
MK27, It's required study for class. But so is TCP, so a hello world example for tcp is good too. I'll look at Linux manual in the mean time.
The initially bewildering part about socket programming is setting up the socket and all the address structs and endianess issues.
Looking at the docs, it appears that for UDP this is identical to setting up a tcp server socket -- that is, you create the socket with bind() -- but then you do not use listen(), you just wait using recvfrom() (which is datagram specific; with TCP you use recv).
Be warned that if you use that GNU example they are creating a local socket. These are somewhat simpler than inet sockets, but you cannot connect two computers with them (they are meant for interprocess communication)! Also, they only exist on *nix systems. So you would want to replace the "make_named_socket" function in that example with something from 16.6 The Internet Namespace.
If you are using linux tho, you may want to try the example as is first since local sockets do not involve any of those addressing or endianess issues.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge