Skip to content

Lorcanomahony1/Java-Socket-Programming-Chat-App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

Network Programming Socket Assignment Design Document

Author: Lorcan O'Mahony
Student ID: G00362689

How to Use the Program

  1. Open the application in Eclipse.
  2. Click the "Run" button on the Server class.
  3. Copy the port number printed to the console.
  4. Run the Client class and enter the port number.
  5. Send messages back and forth between the server and client.
  6. Enter \q to exit the program.

Server

Finding a Free Port Number

  • The user enters a port number as an argument when running the Server function.
  • The server has a default port number of 9023, used if the entered port is unavailable.
  • The isPortFree function checks if the specified port is free.
  • If the port is not free, the findFreePort function loops through port numbers until it finds one that connects.
  • The free port number is printed to the console.

Connecting to a Client

  • The server waits for a client to connect.
  • Upon connection, a new thread is created to handle communication between the client and server.
  • This is managed by a separate function called clientHandlerThread.

Client

Connecting to the Port

  • The client is prompted to enter a port number (use the one printed by the server).
  • When the client and server connect, both initiate the chatting functionality.
  • The server sends a message to the client to start the chat.
  • The client reads the server's output, and if it is not null, it triggers a while loop allowing back-and-forth messaging using input and output streams.

Chat Functionality

Server Side

  • Sends a message to the client to initiate the chat (triggers the client's while loop).
  • Waits for the client's response, which triggers the server's while loop.
  • Prints the client's message.
  • Reads input from the command line using stdIn.readLine().
  • Sends the server's command-line input to the client using out.println.

Server Screenshot

Client Side

  • Waits for input from the server using in.readLine().
  • Upon receiving a message (fromServer), prints it and runs a while loop.
  • The while loop checks if the server sent \q; if so, it exits the loop and ends the chat.
  • Checks if the client entered something into the console using stdIn.
  • If input is provided, sends the message to the server and ends the loop.
  • This triggers the server's while loop, prompting a response.

Client Screenshot

References

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages