java.lang.Objectobjectdraw.Client
public class Client
A Client
makes a connection to another computer (the server) and can
send messages to the server and receive messages back. You will never create a
Client
directly. Instead, create an object that implements the
ClientListener
interface, and pass that object to Network.configure()
so that it will be notified when the user has connected to a server and when
messages come in from that server.
The Client
object is passed to all the ClientListener
methods. You can use that object to send a reply to the server right away, using
the sendMessage()
method, or you can keep the Client
in an instance variable so that you can send messages later when you need to. The
Client
also has methods to determine the name the user entered for
their Client
, and the name and address of the Server
that they joined.
ClientListener
,
Network.configure(String, ServerListener, ClientListener)
Method Summary | |
---|---|
String |
getName()
Get the client name. |
InetSocketAddress |
getServerAddress()
Get the server address. |
String |
getServerName()
Get the server name. |
boolean |
isRunning()
Check if the client is still connected. |
void |
sendMessage(String message)
Send a message to the server. |
void |
shutDown()
Shut down the client, disconnecting it from the server. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.lang.Runnable |
---|
run |
Method Detail |
---|
public String getName()
public InetSocketAddress getServerAddress()
public String getServerName()
public boolean isRunning()
true
if the client is running, false
otherwise.public void sendMessage(String message)
messageReceived()
event.
message
- The message to send.public void shutDown()
clientDisconnected()
message, and the server
listener will receive a channelClosed()
event. Quitting the
program will automatically shut down the client.