+ 2

Infinite chatting application between server and client using socket programming

I want to create an infinite chatting application i have written the code for just one message and i want to modify the code in such a way that there is infinite chatting between server and client but if client don't enter any message after 10 sec server should close its port and i don't how to do it anyone can please help me? My server class public class Server { public static void main(String[] args) { // TODO code application logic heretry{ try{ ServerSocket ss=new ServerSocket(6666); Socket s=ss.accept();//establishes connection DataInputStream dis=new DataInputStream(s.getInputStream()); DataOutputStream dout=new DataOutputStream(s.getOutputStream()); dout.writeUTF("Hello i am your Server"); String str=(String)dis.readUTF(); System.out.println("message= "+str); ss.close(); }catch(Exception e){System.out.println(e);} } }

20th Nov 2020, 4:59 AM
Subhan Ahmed
Subhan Ahmed - avatar
1 Antwort