Server Side

A Java program for Two-way Socket Programming (Server Side)
 avatar
user_9332925630
java
4 years ago
1.2 kB
6
Indexable
//A Java program for Two-way Socket Programming  (Server Side)
package cnlabreport3;
import java.net.*;
import java.io.*;
/**
 * @author aman
 */
public class CNLabReport3 {
    
    public static void main(String[] args) throws IOException {
        
        ServerSocket ss = new ServerSocket (5000);
        System.out.println("Server is connected!!!");
        System.out.println("Waiting for client request!!!");
        Socket s = ss.accept();
        System.out.println("Client request is accepted!!!");
        
        DataInputStream input = new DataInputStream(s.getInputStream());        
        DataOutputStream output = new DataOutputStream(s.getOutputStream());        
        BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
        
        String str = "";
        String str2 ="";
        
        while(!str.equals("bye") && !str2.equals("bye")){
            str=input.readUTF();
            System.out.println("Client says: "+str);   
            str2 = read.readLine();
            output.writeUTF(str2);
        }
        
        input.close();
        output.close();
        read.close();
        ss.close();  
    }   
}
Editor is loading...