examples.example4_two_clients_OO_library
Class Main
java.lang.Object
examples.example4_two_clients_OO_library.Main
public class Main
- extends Object
NetworkingExamples project: examples.example4_two_clients_OO_library.
A simple example of networking (Sockets) in which:
-- A single Server and two Clients exchange information.
-- The Server reads from Client 1, writes to Client 2, reads from Client 2, writes to Client 1, etc.
-- The Clients each read from the Server, then write to the Server, repeatedly.
This is the same example as examples.example3_one_client_OO_library
except the two Clients communicate with each other (instead of the Server communicating
with the sole Client), using the Server as the intermediary.
Run this program on one computer choosing "Server"
and on another computer choosing "Client" and on a third computer choosing "Client" again.
Or, run all/some on the same computer; choose "localhost" as the Server HostName.
NOTE:
1. The Server should be started before the Clients start.
2. Before running this program, you may need to tell your Firewall not to
block the port that this program uses (4444, chosen arbitrarily). In Windows, do so by:
Control Panel ~ Windows Firewall ~ Exceptions tab ~ Add Port
and enter the port number (4444) with any name you like.
See examples.example1_one_client for:
-- Exactly what information the Server and Client exchange in this demo.
-- The 7 Key Statements that are all-you-need-to-know to do networking in Java.
See examples.example2_one_client_OO for this same example
but using an OO structure directly (instead of using a library as this example does).
- Author:
- David Mutchler, based on the Java Tutorials on networking. May, 2009.
|
Constructor Summary |
Main()
|
|
Method Summary |
static void |
main(String[] commandLineArguments)
Asks the user whether she wishes to be the Server or Client,
and constructs whichever she requests. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Main
public Main()
main
public static void main(String[] commandLineArguments)
- Asks the user whether she wishes to be the Server or Client,
and constructs whichever she requests.
- Parameters:
commandLineArguments - Ignored here