Home
Knowledge Base
Credits
Site Map
 


Socket Programming with TCP


Many network applications consist of a pair of programs - a client program and a server program - residing in two different end systems

When these two programs are executed, a client and server process are created, and these processes communicate with each other by reading from and writing to sockets

The socket is the door between the application process and the TCP

Two types of network applications

  1. An application that is an implementation of a protocol standard
    1. FTP
  2. A propriety network application
    1. A design not found in an RFC

 

 

The client initiates contact with the server

  1. Server cannot be dormant
  2. Server must have a socket

Client initiates a TCP connection with the server by creating a socket

Client specifies the address of the server

TCP in the client initiates a three-way handshake and establishes a TCP connection with the server

 

 

 

 

 

 

During the three-way handshake, the server opens a new socket, called a server socket, and invokes the socket's accept() method, which creates a new dedicated socket, called the connection socket, for the client

The TCP connection is a direct virtual pipe between the client's socket and the server's new socket

 

TCP provides reliable byte-stream service - TCP guarantees that the server process will receive each byte from the client's socket in the order sent

Because sockets play a central role in client/server applications, client/server application development is also referred to as socket programming

Stream - a sequence of characters that flow into or out of a process

Two types

  • Input stream - a stream that is attached to some input source for the process, such as standard input (the keyboard) or a socket into which data flows from the internet
  • Output stream - a stream that is attached to some output source for the process, such as standard output (the monitor) or a socket out of which data flows into the internet
 


A sample client/server application

A client reads a line from its standard input and sends the line out its socket to the server

  1. The server reads a line from its connection socket
  2. The server converts the line to uppercase
  3. The server sends the modified line out its connection socket to the client
  4. The client reads the modified line from its socket and prints the line on its standard output