An Chaatroom in Java Programing Language which get message from the Client and the Server send the same message in capitalized form.

You have to just make two classes  in Java Environment 1st TCPClient and 2nd TCPServer.

In TCPClient you have to write this coding.

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.Socket;


public class TCPClient {



public static void main(String[] args) throws Exception {
String sentence;
String modifiedsentence;
for(int i=0; i<10; i++){
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket("178.1.0.0",6789);
DataOutputStream OutToServer = new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
sentence =inFromUser.readLine();
OutToServer.writeBytes(sentence + '\n');
modifiedsentence = inFromServer.readLine();
System.out.println("FROM SERVER:" + modifiedsentence);
clientSocket.close();
}
}

}

In TCPServer you have to write this coding.

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;


public class TCPServer {

public static void main(String[] args) throws Exception{
String clientsentence;
String capitalizedsentence;
ServerSocket welcomeSocket = new ServerSocket(6789);
while(true){
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream OutToClient = new DataOutputStream(connectionSocket.getOutputStream());
clientsentence =inFromClient.readLine();
capitalizedsentence = clientsentence.toUpperCase() + '\n';
OutToClient.writeBytes(capitalizedsentence);
}

}

}

Posted by Unknown On Friday, May 31, 2013 No comments

0 comments:

Post a Comment

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

Like us

    as

    Contact Form

    Name

    Email *

    Message *