Monday, May 3, 2010

Q.WAP to create a client server application in which the client sends some string to the server and server responds by converting the string to upper

//Client:

import java.net.*;
import java.io.*;
class LocalClient1
{
public static void main(String s[]) throws IOException,UnknownHostException
{
String sin, sout;
Socket s=new Socket("localhost",1010);
BufferedReader bclient=new BufferedReader(new InputStreamReader(System.in));
DataOutputStream dos=new DataOutputStream(s.getOutputStream());
BufferedReader bserver=new BufferedReader(new InputStreamReader(s.getInputStream()));
sin=bclient.readLine();
dos.writeBytes(sin+"\n");
sout=bserver.readLine();
System.out.println("Output String:"+sout);
s.close();
}
}


//Server:

import java.net.*;
import java.io.*;
class LocalServer
{
public static void main(String s[]) throws IOException,UnknownHostException
{
String s1, s2;
SreverSocket ss=new ServerSocket(1010);
System.out.println("Listen...");
while(true)
{
Socket s=ss.accept();
BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
DataOutputStream d=new DataOutputStream(s.getOutputStream());
s1=br.readLine();
s2=s1.toUpperCase();
d.WriteBytes(s2+"\n");
s.close();
}

No comments:

Post a Comment