Echo Message in java using TCP/IP

In Internet the traffic is control by strict protocol . There are two types of Internet Protocol (IP).

Types of Internet Protocol(IP)

1. TCP (Transmission Control Protocol ) and
2.UDP (User or Universal  Datagram Protocol)

TCP is connection oriented – reliable protocol which transfer the data in continues streams.once a connection is established, data can be sent bidirectional. It is a two way communication.
UDP is a  connection less ,independent , self contained protocol. Bulk Data  are send and receive  as packets from using UDP.

whether you are sending a packet via TCP or UDP, the packet is sent to an IP address. These packets are forwarded from your computer  to the destination via on Internet router.

Process of Communication

First when client send request to server means that when you load a web page, your computer sends TCP (bytes forms)packets to the web server’s address, then server  send the web page to you as response.
The web server sending a stream of TCP packets as response , which your web browser receive the web pages  and display it to you.


Differ type of Definition for ECHO progrgam

How to make Client Server Chat Program in java using TCP/IP

write a java program  if one computer (Client)  send message and another computer (server) send same message  on ECHO

Example Program of Echo message print in java using TCP/IP connection between client & server

Solution for ECHO Program

First you Open any Editor like Notepad++
write first program and save it.

now  open new File
write second  program and save it.

Source Code for  Server


Source Code for  Client


Output of ECHO Program in JAVA using TCP/IP

First two different cmd(command prompt) window open on   screen

now we seen two different cmd window screen  on monitor now do this step

step-1   e:>javac on cmd screen-1

step-2  e:>javac on cmd screen-1

step-3  e:>java Server2  on cmd screen-1

step-4  e:>java Client2 on cmd screen-2

For Better Understanding see on the below Screenshot

echo in java using tcp-ip
echo in java using tcp-ip


Program Explain

The package is required for socket programming.and The package is required to support i/o operations. and package provide two class
ServerSocket class and socket class

ServerSocket class creates stream socket and connect with specific port ,ip address,host name.
where socket class which is known listen Socket which class creates another socket for listen to the client

readLine() method in BufferedReader object is created to read the input from keyboard (write on console)

GetInputStream() method in InputStreamReader is for receive(read) the input stream where as a parameter to InputStreamReader.
getOutputStream() method in DataOutputStream which sent(write)  output stream  data to other side of  computer.

(Visited 961 times, 4 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *

Reload Image