Class Client
java.lang.Object
java.lang.Thread
fr.r1r0r0.deltaengine.model.engines.network.client.Client
- All Implemented Interfaces:
java.lang.Runnable
public final class Client
extends java.lang.Thread
Client-side class of Network DeltaEngine package.
Uses Socket of Java, you connect to the server once constructor is called.
When connected, you can send objects to the server or receive objects from the server.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
-
Field Summary
Fields Modifier and Type Field Description private java.util.Collection<java.lang.Object>
buffer
private java.net.Socket
connection
private java.io.ObjectInputStream
inputStream
private boolean
interrupted
private java.io.ObjectOutputStream
outputStream
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
Constructors Constructor Description Client(java.lang.String address, int port)
Default constructor. -
Method Summary
Modifier and Type Method Description void
close()
End connection with the serverprivate void
initBuffer()
Initializes internal bufferboolean
isInterrupted()
java.util.Collection<java.lang.Object>
receive()
Retrieve all data received from the server and reset its buffervoid
run()
void
send(java.lang.Object... objects)
Send data to bound serverMethods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
connection
private final java.net.Socket connection -
outputStream
private final java.io.ObjectOutputStream outputStream -
inputStream
private final java.io.ObjectInputStream inputStream -
buffer
private java.util.Collection<java.lang.Object> buffer -
interrupted
private volatile boolean interrupted
-
-
Constructor Details
-
Client
public Client(java.lang.String address, int port) throws java.io.IOExceptionDefault constructor. It will establish a connection with given server address and port- Parameters:
address
- server addressport
- used server port- Throws:
java.io.IOException
- for any exceptions thrown by Socket library
-
-
Method Details
-
run
public void run()- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.lang.Thread
-
send
public void send(java.lang.Object... objects) throws java.io.IOExceptionSend data to bound server- Parameters:
objects
- objects to send- Throws:
java.io.IOException
- default exceptions thrown by Java libraries
-
receive
public java.util.Collection<java.lang.Object> receive()Retrieve all data received from the server and reset its buffer- Returns:
- Collection of objects received
-
initBuffer
private void initBuffer()Initializes internal buffer -
close
public void close()End connection with the server -
isInterrupted
public boolean isInterrupted()- Overrides:
isInterrupted
in classjava.lang.Thread
-