public class SocketHelper extends VertxHelperBase
getOrCreateHelper(Object, ScriptObjectMirror)
to create exactly one instance of this helper
per actor. Pass the actor as an argument.
A confusing aspect of this design is the socket client will
have exactly one socket associated with it, whereas a socket
server can have any number of sockets associated with it.
In any case, there should be only one instance of this class
associated with any actor. This ensures that all the socket
actions and callbacks managed by this instance execute in
a single verticle.
This class supports transmission of strings, images, and binary
numerical data of type byte, double, float, int, long, short,
unsigned byte, unsigned int, and unsigned short, and arrays of
all the numerical type.
If you specify the send type to be "image", then a default
JPG encoding will be used for transmission. Otherwise, the specific
image type encoding that you specify will be used.
For received images, any image type supported by the ImageIO
readers can be accepted, so you just need to specify "image".Modifier and Type | Class and Description |
---|---|
static class |
SocketHelper.ByteArrayBackedInputStream
Input stream backed by a list of byte arrays.
|
class |
SocketHelper.SocketWrapper
Wrapper for connected TCP sockets.
|
VertxHelperBase.AccessorVerticle
HelperBase.DATA_TYPE
_verticle, _vertx
_actor, _currentObj
Constructor and Description |
---|
SocketHelper(java.lang.Object actor,
jdk.nashorn.api.scripting.ScriptObjectMirror helping)
Constructor for SocketHelper for the specified actor.
|
Modifier and Type | Method and Description |
---|---|
static SocketHelper |
getOrCreateHelper(java.lang.Object actor,
jdk.nashorn.api.scripting.ScriptObjectMirror helping)
Get or create a helper for the specified actor.
|
void |
openClientSocket(jdk.nashorn.api.scripting.ScriptObjectMirror socketClient,
int port,
java.lang.String host,
java.util.Map<java.lang.String,java.lang.Object> options)
Create a client-side socket on behalf of the specified
JavaScript SocketClient object.
|
void |
startServer(jdk.nashorn.api.scripting.ScriptObjectMirror socketServer,
java.util.Map<java.lang.String,java.lang.Object> options)
Create a server that can accept socket connection requests
on behalf of the specified JavaScript SocketServer object.
|
static java.lang.String[] |
supportedReceiveTypes()
Return an array of the types supported by the current host for
receiveType arguments.
|
static java.lang.String[] |
supportedSendTypes()
Return an array of the types supported by the current host for
sendType arguments.
|
_issueOrDeferResponse, _processPendingJob, _setBusy, closeVertx, getHelper, getImageTypes, reset, submit, undeploy
_appendNumericToBuffer, _appendToBuffer, _error, _error, _error, _error, _extractFromBuffer, _issueResponse, _removeDuplicates, _sizeOfType, _toJavaBytes, _toJSArray, getHelping
public SocketHelper(java.lang.Object actor, jdk.nashorn.api.scripting.ScriptObjectMirror helping)
actor
- The actor that this will help.helping
- The JavaScript object that this is helping.public void openClientSocket(jdk.nashorn.api.scripting.ScriptObjectMirror socketClient, int port, java.lang.String host, java.util.Map<java.lang.String,java.lang.Object> options)
socketClient
- The JavaScript SocketClient instance.port
- The remote port to connect to.host
- The remote host to connect to.options
- The options (see the socket.js JavaScript module).public static SocketHelper getOrCreateHelper(java.lang.Object actor, jdk.nashorn.api.scripting.ScriptObjectMirror helping)
actor
- Either a JavaScript actor or a RestrictedJavaScriptInterface.helping
- The JavaScript object that this is helping.public static java.lang.String[] supportedReceiveTypes()
public static java.lang.String[] supportedSendTypes()
public void startServer(jdk.nashorn.api.scripting.ScriptObjectMirror socketServer, java.util.Map<java.lang.String,java.lang.Object> options)
socketServer
- The JavaScript SocketServer instance.options
- The options (see the socket.js JavaScript module).