This section provides a tutorial example on how to write a simple socket communication client program, SocketClient.pl, which creates a socket and makes a connection request to a remote socket communication server.
Instead of using the telnet program, we can use the following program, SocketClient.pl,
to communicate with ReverseEchoer.pl:
Setting $| to 1 is to turn on auto flush to the default file handle. In order to
turn on auto flush to SOCK, I have to use select() function to switch default file
handles.
Now, run ReverseEchoer.pl, then run SocketClient.pl in a separate command
window. If you type in the same text as in the previous test, you will get
the following output:
Client host: 127.0.0.1
Client port: 1024
Server host: 127.0.0.1
Server port: 8888
Welcome to Reverse Echo Server.
Fish, I love you and respect you very much.
.hcum yrev uoy tcepser dna uoy evol I ,hsiF
But I will kill you dead before this day ends.
.sdne yad siht erofeb daed uoy llik lliw I tuB
.