Simple network console chat on Java
In this post I will show you simple example of network chat on Java. Let's start with our task. Task You need to implement console network chat. There must be a server instance and a client instance. Server starts, wait for single connection. Client starts, connects to server. Than client can write a message in its console. Message will be send to server and appears in server console. Server can do the same. Client and server can close the chat. Let's start. First, create basic class for handling typical operations by client and server in our task: get input from Std.in, set output to socket, get input from socket. package chat; import java.io.IOException; import java.io.PrintWriter; import java.net.Socket; import java.util.Scanner; public class Client { private Scanner in; private Scanner input; private PrintWriter out; private Thread threadIn; private Thread threadOut; public Client(Socket sock, String name) { try { in =...