Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.*;
- public class TcpEchoClient
- {
- public static void main (String[] args) throws IOException {
- Socket socket = null;
- try {
- socket = new Socket("192.168.1.3", 8888);
- } catch (IOException e) {
- System.out.println("Błąd podczas tworzenia socketu!");
- e.printStackTrace();
- }
- BufferedReader in = null;
- try {
- in = new BufferedReader(new InputStreamReader(socket.getInputStream ()));
- } catch (IOException e) {
- e.printStackTrace();
- }
- PrintWriter out = null;
- try {
- out = new PrintWriter(socket.getOutputStream(), true);
- } catch (IOException e) {
- e.printStackTrace();
- }
- BufferedReader stdIn = new BufferedReader (new InputStreamReader(System.in));
- String fromClient, fromServer;
- do
- {
- System.out.print ("? ");
- fromClient = stdIn.readLine();
- out.println (fromClient);
- fromServer = in.readLine ();
- System.out.println ("Server: " + fromServer);
- }
- while (! fromServer.equals ("quit"));
- in.close ();
- out.close ();
- socket.close ();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement