Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
30 views

Client Server Application For Chat

This document describes a client-server chat program written in Java. The client code imports socket and input/output stream classes and creates a socket connection to a server running on port 3148. It sends the user's input to the server and prints any received messages. The server code also imports socket and I/O classes and creates a server socket listening on port 3148. When a client connects, it prints the client's message and sends any input back to that client. The output shows the client and server classes being compiled and run, with the client sending a message that is received and printed by the server.

Uploaded by

Beginner Man
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Client Server Application For Chat

This document describes a client-server chat program written in Java. The client code imports socket and input/output stream classes and creates a socket connection to a server running on port 3148. It sends the user's input to the server and prints any received messages. The server code also imports socket and I/O classes and creates a server socket listening on port 3148. When a client connects, it prints the client's message and sends any input back to that client. The output shows the client and server classes being compiled and run, with the client sending a message that is received and printed by the server.

Uploaded by

Beginner Man
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

CLIENT SERVER APPLICATION FOR CHAT PROGRAM: CLIENT:

import java.net.*; import java.io.*; import java.lang.*; public class client { public static void main(String arg[])throws IOException { Socket soc=new Socket("0.0.0.0",3148); InputStream is=soc.getInputStream(); OutputStream os=soc.getOutputStream(); PrintWriter PW=new PrintWriter(os); BufferedReader br=new BufferedReader(new InputStreamReader(is)); BufferedReader br1=new BufferedReader(new InputStreamReader(System.in)); PW.println(br1.readLine()); PW.flush(); System.out.println("MSG from Server"+br.readLine()); } }

SERVER:

import java.net.*; import java.io.*; import java.lang.*; public class server { public static void main(String arg[])throws IOException { ServerSocket ss=new ServerSocket(3148); System.out.println("Server connecting"+ss); Socket soc=ss.accept(); System.out.println("Client Started"+soc); InputStream is=soc.getInputStream(); OutputStream os=soc.getOutputStream(); PrintWriter PW=new PrintWriter(os); BufferedReader br=new BufferedReader(new InputStreamReader(is)); BufferedReader br1=new BufferedReader(new InputStreamReader(System.in)); System.out.println("MSG from Client"+br.readLine()); PW.println(br1.readLine()); PW.flush(); } } OUTPUT: CLIENT: z:\java>javac client.java z:\java>java client computer networks SERVER: z:\java>javac server.java z:\java>java server msg from client:computer networks

You might also like