Skip to content

fabiolee/asynchronous-socket-programming

Repository files navigation

Asynchronous Socket Programming in Java

I have this question long time ago, how to transfer data from one client to another through a server? After some Google search, I think the keyword that I am looking for should be "Asynchronous Socket Programming".

I manage to find the keyword, but I fail to find a simple example in Java. So, I decide to write one myself based on Socket Programming tutorial by S.Prasanna.

First of all, I am going to create two projects, TCPServer & TCPClient.
  1. TCPServer having three threads for captures input (Main.java), read clients output (ReadThread.java) & read client new connection (ConnectThread.java).
  2. TCPClient having two threads for captures input (Main.java) & read server output (ReadThread.java).

Here are some demo scenes:

First of all, open the TCPServer program.
Open two TCPClient program, connect to TCPServer.
Send message from TCPClient A program to TCPServer.
Send message from TCPClient B program to TCPServer.
Send message from TCPServer to both TCPClient programs.
Lastly, I try to disconnect one of the TCPClient program.

This is my first socket connection program, correct me if I make any mistake.

About

Asynchronous Socket Programming in Java

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages