Laynetworks  
Web laynetworks.com Google
Home | Site Map | Tell a friends
Management Tutorials
Download
Tutorials
History
Computer Science
Networking
OS - Linux and Unix
Source Code
Script & Languages
Protocols
Glossary
IGNOU
Quiz
About Us
Contact Us
Feedback
 
Sign up for our Email Newsletter
 
Get Paid for Your Tech Turorials / Tips

 

 

Home > Networking > TCP
Page : 1 2 3 4 5 6 7 8 9 10 11 12 13
TCP
Next >

Example of using BSD sockets: "Echo Server"

Design
This program implements a simple client-server program. The client connects to the server via TCP and sends it any ASCII text message. The server replies to the client with the same message. The client then outputs the message the server returned.

The message sent from the client to the server consists of two parts. The first byte sent contains the length of the message, not including itself. The rest of the message is the message to be repeated back from the server to the client. The reply message is in the same format. The length is passed in order to allow the server to be sure it has read all available data. Compiling

To compile this program, go to any Solaris machine. Copy the following files to any subdirectory in your Unix home directory:

Type "make" in the directory where the source code is located. Two binaries should be produced: "client" and "server". Telnet to another machine. Run "server" on one machine and "client" on the other machine.

Usage

Server: The server is started with a single command line argument, the port number. The server will wait on this port until contact is made by the client. Once the server replies to the message sent by the client, it exits.
Example: #server 2000 (note: the pound sign indicates the Unix prompt)

Client:
The client is started with three command line arguments. These arguments include the host, port number, and message to send. The client will then send the given message to the given host and port number and wait for a reply. Once the reply is recieved, the client exits.
Example:#client ece2.ece 2000 "This is a test of the emergency broadcast system"

Design Tradeoffs

The program is limited to transmitting a message containing 255 characters. This could be improved by seperating the message into smaller chunks. The server will continue to receive the chunks until all has been sent. This could be done with minimal modification of code. All the is needed is some sort of "all done" message sent between the client and server.

NOTE: There is a quick script called "Test" that will run a simple test case.

 
Page : 1 2 3 4 5 6 7 8 9 10 11 12 13
 
Donation | Useful links | Link to Laynetworks.com | Legal | SharePoint Development
Copyright © 2000-2010 Lay Networks All rights reserved.