public class Client extends java.lang.Thread implements Deliverer
The client is asynchronous and will notify the encapsulating processing applet when data is received over the network or when the network connection is broken.
The methods that the encapsulating processing applet can implement are:
void clientReceiveEvent(RemoteAddress serverAddress, String data);
void clientReceiveEvent(RemoteAddress serverAddress, byte[] data);
void clientDisconnectedEvent(RemoteAddress serverAddress);
RemoteAddress
,
Server
Modifier and Type | Field and Description |
---|---|
static int |
bufferSize |
Constructor and Description |
---|
Client(processing.core.PApplet parent,
java.lang.String ip,
int port)
This constructs a new client and initializes it.
|
Modifier and Type | Method and Description |
---|---|
boolean |
connect()
This method establishes the connection and starts the thread that listens to the data.
|
void |
disconnect()
This method tears down the connection to the server and stops the worker thread.
|
void |
dispose()
This is called by the encapsulating processing applet.
|
void |
run()
This method perform the asynchronous reception of data.
|
int |
send(byte data)
This client sends data to the server.
|
int |
send(byte[] data)
This client sends data to the server.
|
int |
send(double data)
This client sends data to the server.
|
int |
send(int data)
This client sends data to the server.
|
int |
send(java.lang.String data)
This client sends data to the server.
|
void |
throwReceiveEventByteArray(java.nio.ByteBuffer bf)
This is a helper method used to notify the encapsulating processing
applet that we have received data.
|
void |
throwReceiveEventString(java.nio.ByteBuffer bf)
This is a helper method used to notify the encapsulating processing
applet that we have received data.
|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public Client(processing.core.PApplet parent, java.lang.String ip, int port)
parent
- the encapsulating processing appletip
- the ip or address to connect toport
- the port to connect topublic void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void throwReceiveEventByteArray(java.nio.ByteBuffer bf)
throwReceiveEventByteArray
in interface Deliverer
bf
- the ByteBuffer containing the datapublic void throwReceiveEventString(java.nio.ByteBuffer bf) throws java.nio.charset.CharacterCodingException
throwReceiveEventString
in interface Deliverer
bf
- the ByteBuffer containing the datajava.nio.charset.CharacterCodingException
public boolean connect()
public int send(java.lang.String data)
The method returns -1 and throws a disconnectedEvent if the connection has been broken.
data
- the data to be sentpublic int send(int data)
The method returns -1 and throws a disconnectedEvent if the connection has been broken.
data
- the data to be sentpublic int send(double data)
The method returns -1 and throws a disconnectedEvent if the connection has been broken.
data
- the data to be sentpublic int send(byte data)
The method returns -1 and throws a disconnectedEvent if the connection has been broken.
data
- the data to be sentpublic int send(byte[] data)
The method returns -1 and throws a disconnectedEvent if the connection has been broken.
data
- the data to be sentpublic void disconnect()
public void dispose()