A private groupchat that 2+ devices can share over WiFi.
- Java
- IntelliJ
- Client.java - Establishes a client socket, which is composed of 2 sockets (1 to send files, 1 to send text). Also, creates a chat GUI.
- FileHandler.java - Reads a file over a particular socket. The server runs this as a thread for each client.
- ChatHandler.java - Reads text continually over a particular socket until the socket is closed. Also, relays each message back to all the clients. The server runs this as a thread for each client.
- Server.java - Establishes a server socket, which is composed of 2 sockets (1 to accept files, 1 to accept text). Continually creates new server sockets (threads/handelers) to accept more and more new clients.
- Pick a device to use as a server (e.g. your laptop). Download the 4 files above on that device.
- Edit the Server file to include the Internet address and port appropriate for your device. Edit lines 11-12:
String host = "192.168.1.130"; // This should be your private IP address
int port = 1111; // Pick any port on your device
InetAddress inetAddress = InetAddress.getByName(host);
ServerSocket serverSocket = new ServerSocket(port, 5, inetAddress);
- Start the server by running the Server file. You should then see a printed confirmation that the Server is running.
$ javac Server.java
$ java Server
Server created. Waiting for at least 1 client to connect...
- Next, each device using the group chat should download Client.java.
- Mimic step #2 on Client.java to make sure the host and port on the client (lines 32-33) match the server file (lines 11-12).
- Compile and run Client.java. Each user should answer the 2 questions in the terminal. Then, the program will initialilze the chat GUI: