Javatpoint Logo
Javatpoint Logo

Perl Socket Programming


What is Socket Programming?

A socket is a procedure which helps to establish a virtual connection between different processes over a network.

A computer receives and sends information by the various applications running on it. This information is routed to the system by a unique IP address assigned to it. The data send during communication is in a "Protocols" format. These Protocols are the rules which are accepted by all communication partners. There are many protocols format with different objectives in socket communication. The most commonly used protocol is TCP/IP protocol.

For a server-client program, we need to create two Perl scripts. One for server and other for client. These two consoles will communicate through each other. You can enter data on client side which will be displayed on server side console.


Perl Creating a Server

The following steps are followed to create a socket server.

  • Creating socket using socket call.
  • Binding socket using bind call to a port address.
  • Listening socket using listen call at a port address.
  • Accepting client connections using accept call.

Perl Creating a Client

The following steps are followed to create a client socket.

  • Creating socket using socket call.
  • Connecting socket using connect call to the server.

Perl Socket Programming Example

In this program we have displayed client side data Hello World! on server side console.

Server side script server.pl

Client side script client.pl

Output:

Perl Socket programming 1

Perl Socket Reading and Writing Program

In this client-server program, we'll take input from the users on client console. This input will be displayed on the server's console through client-server communication.

Here the server side scripting will remain same as the earlier one.

Server side script server.pl

Client side script client.pl

Output:

Perl Socket programming 2



Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA