Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintStream;
- import java.net.Socket;
- import java.net.UnknownHostException;
- public class Client implements Runnable {
- static Socket communicationSocket = null;
- static BufferedReader serverInputStream = null;
- static PrintStream serverOutputStream = null;
- static BufferedReader consoleInput = null;
- public static void main(String[] args) {
- try {
- communicationSocket = new Socket("localhost", 9000);
- serverOutputStream = new PrintStream(communicationSocket.getOutputStream());
- serverInputStream = new BufferedReader(new InputStreamReader(communicationSocket.getInputStream()));
- consoleInput = new BufferedReader(new InputStreamReader(System.in));
- new Thread(new Client()).start();
- String input;
- while(true) {
- input = serverInputStream.readLine();
- System.out.println(input);
- if(input.startsWith(">>>Dovidjenja ")) {
- break;
- }
- }
- communicationSocket.close();
- } catch (UnknownHostException e) {
- System.out.println("UNKNOWN HOST");
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- @Override
- public void run() {
- try {
- String msg;
- while(true) {
- msg = consoleInput.readLine();
- if(msg.equals("//quit")) {
- break;
- }
- serverOutputStream.println(msg);
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement