LAST EDIT: 03 Kislev 5759, 23 Nov 1998
Here is an example in pseudo-code of 2 processes communicating via internet datagram.
sd = socket ( PF_INET, SOCK_DGRAM, def_proto ) sname = ( INADR_ANY, undef_port ) bind ( sd, sname, sname_len ) call getsockname to get the port we are listening on, and print it. read ( sd, &buf, buflen ) close ( sd )
Click here to see C code for the receiver.
On the command line we'll specify which host & which port to send to:
sd = socket ( PF_INET, SOCK_DGRAM, def_proto ) other_sname = ( host & port as specified on command line ) sendto ( sd, "Hello my friend", msg_len, other_sname, other_sname_len ) close ( sd )
Click here to see C code for the sender.