Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.*;
- public class Client {
- public static void main(String[] args) throws IOException {
- Socket Socket = null;
- PrintWriter out = null;
- BufferedReader in = null;
- Boolean Connected = true;
- String HostName = "DELLLAB_08";
- try {
- Socket = new Socket(HostName, 4444);
- out = new PrintWriter(Socket.getOutputStream(), true);
- in = new BufferedReader(new InputStreamReader(Socket.getInputStream()));
- } catch (UnknownHostException e) {
- System.err.println("Don't know about host: HostName.");
- System.exit(1);
- } catch (IOException e) {
- System.err.println("Couldn't get I/O for the connection to: taranis.");
- System.exit(1);
- }
- BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
- String fromServer;
- String fromUser = null;
- while (Connected)
- {
- try{
- Thread.currentThread().sleep(10);
- }
- catch(InterruptedException e){}
- //recieve data
- if((fromServer = in.readLine()) != null)
- {
- System.out.println("Server: " + fromServer);
- if (fromServer.equals("Bye."))
- break;
- }
- //fromUser = "lol";
- fromUser = stdIn.readLine();
- if (fromUser != null)
- {
- System.out.println("Client: " + fromUser);
- out.println(fromUser);
- out.flush();
- }
- }
- out.close();
- in.close();
- stdIn.close();
- Socket.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement