We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
ouTPUT:
SERVER:
pied corel Pere
ier prrereteriae ts
eNO esd
ee
Soares
a
ee ens
ey Sriemeneetn
emrresg fe sete eet Ay
Riera eerin ret sy
Roeenee piaseser ceoernrnt atin SOs crate Sec etee etre
pieectents
CLIENT:
eae See a
Se cca Sect ate
eee etry
RESULT:
‘Thus the program was executed and output is verified successfully.b. Chat
CHAT APPLICATION
AIM:
To write a network program for implementing chat using TCP socket.
ALGORITHM:
Client sends the request to server
‘Server runs the request and the connection with the client that has requested the server.
‘The alient sends the message to server.
The server process it and itis displayed (ie) replier by sending the message to client also
displayed.
5. Stop the program.
Fens
SERVER PROGRAM:
Import java.io.*;
import java.net";
public class chatserver
{
public static void main(String args[)throws Exception
{
DatalnputStream din=nutl;
DataQutputStream dout=null;
‘Socket c=null;
ServerSocket m=null;
DatainputStream stdin=new DatalnputStream(System.in);ty
{
m=new ServerSocket(68);
c=maceept0;
din=new DatalnputStream(c.gelinputStream();
dout=new DataOutputStream(c.getOutputStreamd);
)
catch(Exception e)
t
y
while(l=null)
ra
String m2;
‘System out printin(‘Server’);
whiledrue)
{
String mt=din.readLine(;
‘System out printin(‘Message from client."*m1);
System out prntin¢n\n Enter the message...);
m2sstdin readtineQ;
doutwriteByles("+m2);
doutwiriteBytes("w);
y
?din.closed;
out close();
c.close();
maclose(;
+
}
CLIENT PROGRAI
import java.io.";
import java.net
public class chatelient
{
public static void main(String args{)throws Exception
{
Socket c=null
DatalnputStream uin=null;
DatainputStream di
ll;
DataOutputStream dout=null;
ty
{
c=new Socket("localhost",68);
uin=new DatalnputStream(System in);
din=new DatainputStream(c.getinputStream();
dout=new DataOutputStream(c.getOutputStreamd);