Answer to Question #249960 in Java | JSP | JSF for vovo

Question #249960

create a java program for Two Way Chat Application using Java Socket Programming


1
Expert's answer
2021-10-13T20:39:09-0400
import java.io.*;  
import java.net.*;  
public class Server{  
    public static void main(String[] args){  
    try{  
        ServerSocket server_socket=new ServerSocket(5555);  
        Socket socket=server_socket.accept();  
        DataInputStream d=new DataInputStream(socket.getInputStream());  
        String  str1=(String)d.readUTF();  
        System.out.println("Message: "+str1);  
        server_socket.close();  
    }
    catch(Exception e){
        System.out.println(e);
        
    }  
    }  
}  


import java.io.*;  
import java.net.*;  
public class Client{  
public static void main(String[] args) {  
try{      
    Socket socket=new Socket("localhost",5555);  
    DataOutputStream d2=new DataOutputStream(socket.getOutputStream());  
    d2.writeUTF("Hello Server");  
    d2.flush();  
    d2.close();  
    socket.close();  
    }
    catch(Exception e){
        System.out.println(e);
        
    }  
    }  
} 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS