public class Client { public static void main(String[] args){ try{ ServerSocket ss = new ServerSocket(6666); Socket s = ss.accept(); DataInputStream din = new DataInputStream(s.getInputStream()); String str = din.readUTF(); System.out.println("Message received: " + str); ss.close(); }catch(Exception e){ System.out.println(e); } } }
public class Server { public static void main(String[] args){ int port = 6666; String ipAdress = "localhost"; try{ Socket s = new Socket(ipAdress, port); DataOutputStream dout = new DataOutputStream(s.getOutputStream()); dout.writeUTF("Hello Server"); dout.flush(); dout.close(); s.close(); }catch(Exception e){ System.out.println(e); } } }
public class Client { public static void main(String[] args){ try{ ServerSocket ss = new ServerSocket(6666); Socket s = ss.accept(); DataInputStream din = new DataInputStream(s.getInputStream()); String str = din.readUTF(); System.out.println("Message received: " + str); ss.close(); }catch(Exception e){ System.out.println(e); } } }
public class Server { public static void main(String[] args){ int port = 6666; String ipAdress = "localhost"; try{ Socket s = new Socket(ipAdress, port); DataOutputStream dout = new DataOutputStream(s.getOutputStream()); dout.writeUTF("Hello Server"); dout.flush(); dout.close(); s.close(); }catch(Exception e){ System.out.println(e); } } }
Du måste vara medlem för att kunna kommentera
Flashback finansieras genom donationer från våra medlemmar och besökare. Det är med hjälp av dig vi kan fortsätta erbjuda en fri samhällsdebatt. Tack för ditt stöd!
Swish: 123 536 99 96 Bankgiro: 211-4106