import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;
public class Client {
public static void main(String args[]) throws IOException {
String question, answer, username, exit_line="/exit";
Scanner in = new Scanner (System.in);
Socket socket = new Socket("127.0.0.1",1742);
Scanner sockIn = new Scanner(socket.getInputStream());
PrintStream sockOut = new PrintStream(socket.getOutputStream());
System.out.print("Username: ");
username = in.nextLine();
sockOut.println(username+"\n");
answer = sockIn.nextLine();
System.out.println(answer);
do{
question=in.nextLine();
sockOut.println(username+": "+question+"\n");
answer=sockIn.nextLine();
System.out.println(answer);
}while (!(question.equals(exit_line)));
socket.close();
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.