public abstract class NetworkConnection extends Object
Type | Property and Description |
---|---|
javafx.beans.property.ReadOnlyBooleanProperty |
connectionActive |
Modifier and Type | Field and Description |
---|---|
protected Map<Class<?>,DataParser<? super Serializable>> |
parsers |
Constructor and Description |
---|
NetworkConnection() |
Modifier and Type | Method and Description |
---|---|
<T extends Serializable> |
addParser(Class<T> cl,
DataParser<T> parser)
Register a parser for specified class.
|
abstract void |
close() |
javafx.beans.property.ReadOnlyBooleanProperty |
connectionActiveProperty() |
Map<Class<?>,DataParser<? super Serializable>> |
getParsers() |
protected void |
handleError(Exception e) |
boolean |
isConnectionActive()
Gets the value of the property connectionActive.
|
protected void |
onConnectionClosed() |
protected void |
onConnectionOpen() |
void |
send(Serializable data)
Send data to the machine at the other end using UDP protocol.
|
void |
send(Serializable data,
NetworkProtocol protocol)
Send data to the machine at the other end using specified protocol
|
protected void |
sendClosingMessage()
Send a message (hint) that this end of connection is about
to close
|
protected abstract void |
sendTCP(Serializable data) |
protected abstract void |
sendUDP(Serializable data) |
void |
setExceptionHandler(Consumer<Throwable> exceptionHandler) |
void |
setOnConnectionClosed(Runnable onConnectionClosed) |
void |
setOnConnectionOpen(Runnable onConnectionOpen) |
void |
setParsers(Map<Class<?>,DataParser<? super Serializable>> parsers) |
protected static byte[] |
toByteArray(Serializable data) |
public final javafx.beans.property.ReadOnlyBooleanProperty connectionActiveProperty
isConnectionActive()
protected Map<Class<?>,DataParser<? super Serializable>> parsers
public Map<Class<?>,DataParser<? super Serializable>> getParsers()
public void setParsers(Map<Class<?>,DataParser<? super Serializable>> parsers)
public final javafx.beans.property.ReadOnlyBooleanProperty connectionActiveProperty()
isConnectionActive()
public boolean isConnectionActive()
public void setOnConnectionOpen(Runnable onConnectionOpen)
protected void onConnectionOpen()
public void setOnConnectionClosed(Runnable onConnectionClosed)
protected void onConnectionClosed()
protected void handleError(Exception e)
protected void sendClosingMessage()
public <T extends Serializable> void addParser(Class<T> cl, DataParser<T> parser)
cl
- data structure classparser
- the data parserpublic void send(Serializable data)
data
- the data objectpublic void send(Serializable data, NetworkProtocol protocol)
data
- the data objectprotocol
- the protocol to useprotected abstract void sendUDP(Serializable data)
protected abstract void sendTCP(Serializable data)
public abstract void close()
protected static byte[] toByteArray(Serializable data) throws Exception
Exception
Copyright © 2018. All rights reserved.