Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.*;
  3. public class MyClient{
  4.     public MyClient(String ip, int port){
  5.         String message;
  6.         try{
  7.             Socket me = new Socket(ip, port);
  8.             System.out.println("Server connected");
  9.             DataInputStream dis = new DataInputStream(me.getInputStream());
  10.             DataOutputStream dos = new DataOutputStream(me.getOutputStream());
  11.  
  12.             message = (String) dis.readUTF();
  13.             System.out.println("Message received : " + message);
  14.             dos.writeUTF("GG");
  15.             me.close();
  16.             System.out.println("Closed");
  17.         }catch(Exception e){
  18.             System.out.println(e);
  19.         }
  20.     }
  21.     public static void main(String[] args){
  22.         MyClient server = new MyClient("localhost",10074);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement