0% found this document useful (0 votes)
5 views

Java Pra 16

Uploaded by

Darshan Patil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Java Pra 16

Uploaded by

Darshan Patil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

//server

import java.io.*;

import java.net.*;

public class ChattingS

static int count=0;

public static void main(String args[])

int sport=100;

String s="";

try

ServerSocket ss = new ServerSocket(sport);

System.out.println("Server is started...");

Socket sk= ss.accept();

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

DataInputStream dis = new DataInputStream(sk.getInputStream());

DataOutputStream dos = new DataOutputStream(sk.getOutputStream());

while(sk.isConnected())

if(s.equals("exit"))

System.exit(1);

System.out.println("\nEnter message for client:");

s = br.readLine();

dos.writeUTF(s);
s = dis.readUTF();

System.out.println("\nClient msg:"+s);

sk.close();

catch(Exception e)

System.out.println("Exception hello:"+e);

e.printStackTrace();

//client

import java.io.*;

import java.net.*;

public class ChattingC

public static void main(String args[]) throws Exception

try

int sport=100;

Socket sk;

String s="";

InetAddress ia =InetAddress.getByName("siddhipatankar");

sk = new Socket(ia,sport);
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));

DataInputStream dis= new DataInputStream(sk.getInputStream());

DataOutputStream dos= new DataOutputStream(sk.getOutputStream());

while(true)

if(s.equals("exit"))

System.exit(1);

s = dis.readUTF();

System.out.println("\nMsg From server:"+s);

System.out.println("\nEnter msg for server:");

s=br.readLine();

dos.writeUTF(s);

catch(Exception e)

System.out.println("error"+e);

You might also like