Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Server.java
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.io.*;
- class Server implements Runnable{
- static ServerSocket ss;
- Socket s;
- public void run(){
- try{
- BufferedReader fromClient = new BufferedReader(new InputStreamReader(s.getInputStream()));
- PrintStream toClient = new PrintStream(s.getOutputStream());
- String ip = "";
- while((ip=fromClient.readLine())!=null){
- System.out.println(ip);
- toClient.println(ip.toUpperCase());
- if(ip.equals("bye")) break;
- }
- } catch(Exception e){e.printStackTrace();}
- }
- Server(Socket s){
- this.s = s;
- }
- public static void main(String[] args) throws IOException{
- ss = new ServerSocket(9812);
- while(true){
- new Thread(new Server(ss.accept())).start();
- }
- }
- }
- //Client.java
- import java.net.Socket;
- import java.io.*;
- class Client{
- public static void main(String[] args){
- try{
- Socket s = new Socket("localhost", 9812);
- BufferedReader fromServer = new BufferedReader(new InputStreamReader(s.getInputStream()));
- PrintStream toServer = new PrintStream(s.getOutputStream());
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- System.out.println("Enter a string to capitalize.");
- String ip;
- while(!(ip=br.readLine()).equals("bye")){
- toServer.println(ip);
- System.out.println(fromServer.readLine());
- }
- s.close();
- } catch(Exception e){e.printStackTrace();}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement