A Simple Internet Datagram Example (Pseudo-code)

LAST EDIT:   03 Kislev 5759, 23 Nov 1998

Here is an example in pseudo-code of 2 processes communicating via internet datagram.

The receiver (server):

	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.

The sender (client):

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.


This page maintained by Haim Roman (roman@mail.jct.ac.il), one of the lab instructors.
Office: room 230, Wyler Building, Sundays - Thursdays, 13:30 - 14:30.
Telephone: 02-675-1207