You are on page 1of 2

SOCKET PROGRAMMING

Lab # 3

LAB # 3
SOCKET PROGRAMMING OBJECTIVE
1. Understand socket programming with TCP and UDP. 2. Develop UDP client/server programs for a simple application.

INTRODUCTION
Sockets are a mechanism that allows programs to communicate, either on the same machine or across a network. A program that wishes to receive a connection from another program, asks the operating system to create a socket and bind it to some port. Then the program sits and listens on the socket it has created to receive incoming connections. The other program also creates a socket for communicating with the receiver. The caller needs to specify the IP address and the port number of the receiving end. If all goes well, and as we will see shortly, the two programs establish a communication through the network using their sockets. The two programs may exchange information, each by writing to and reading from the socket it has created.

ASSIGNMENT
1. Develop a simple application over UDP, using port No. 5465 The client sends the message Hello World to server. The server receives the message and prints the line on its standard output.

CE403:Advanced Principles of Operating System

SOCKET PROGRAMMING

Lab # 3

Server.pluse IO::Socket::INET; $server=IO::Socket::INET>new(LocalPort=>5465,Proto=>'UDP'); $server->recv($msg,1024); print("msg= %s",$msg); OUTPUT [[guest@Fedora607m ~]$ vi ali9.prl [guest@Fedora607m ~]$ perl ali9.prl msg= %sName:Shahab Ali,Roll#200,Section:7D[60 msg= %sName:Shahab Ali,Roll#200,Section:7D[guest@Fedora6 07m ~]$

Client.pl use IO::Socket::INET; $client=IO::Socket::INET>new(PeerPort=>5465,Proto=>'UDP',Peer Addr=>'127.0.0.1'); $client->send("Name:Shahab Ali,Roll#200,Section:7D"); [guest@Fedora607m ~]$ vi ali10.prl [guest@Fedora607m ~]$ perl ali10.prl

2. Develop a simple application over UDP, using port No. 5888 The client sends number X and Y to server. The server receives the two number from client and send X+Y to client and also prints the line on its standard output. Server.pl Client.pl

CE403:Advanced Principles of Operating System

You might also like