Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Make two different projects, first run server than client. Server will write on console "Server started" than run client it will ask your name, type your name press ok . Your name will be sent to server and server will reply saying hello to you. </p> <p>Here is server code</p> <pre><code>import java.net.*; import java.io.*; import javax.swing.*; public class Server { public static void main(String[] args) { try{ ServerSocket ss= new ServerSocket(2224); System.out.println("Serever started"); while(true) { Socket s=ss.accept(); InputStream is=s.getInputStream(); InputStreamReader isr=new InputStreamReader(is); BufferedReader br=new BufferedReader(isr); OutputStream os=s.getOutputStream(); PrintWriter pw=new PrintWriter(os); String name=br.readLine(); String message="Hello "+name+"from server"; pw.println(message); pw.flush(); } } catch(Exception exp) { System.out.println("Excepttion occured"); } } } </code></pre> <p>Here is client code</p> <pre><code>import java.net.*; import java.io.*; import java.util.Scanner; import javax.swing.*; public class Client { public static void main(String[] args) throws IOException { Socket s=new Socket("localhost",2224); InputStream is=s.getInputStream(); InputStreamReader isr=new InputStreamReader(is); BufferedReader br=new BufferedReader(isr); OutputStream os=s.getOutputStream(); PrintWriter pw=new PrintWriter(os,true); String message = JOptionPane.showInputDialog("Give your name"); pw.println(message); pw.flush(); String servermessage = br.readLine(); JOptionPane.showMessageDialog(null, servermessage); s.close(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload