io.socket
Class IOConnection

java.lang.Object
  extended by io.socket.IOConnection
All Implemented Interfaces:
IOCallback

 class IOConnection
extends java.lang.Object
implements IOCallback

The Class IOConnection.


Field Summary
(package private)  java.util.HashMap<java.lang.Integer,IOAcknowledge> acknowledge
          Acknowledges.
static IOCallback DUMMY_CALLBACK
          A dummy callback used when IOConnection receives a unexpected message.
static java.lang.String FRAME_DELIMITER
           
(package private) static java.util.logging.Logger logger
          Debug logger
static java.lang.String SOCKET_IO_1
          Socket.io path.
 
Method Summary
 void emit(SocketIO socket, java.lang.String event, IOAcknowledge ack, java.lang.Object... args)
          emits an event from SocketIO to the IOTransport.
protected  void error(SocketIOException e)
          Populates an error to the connected IOCallbacks and shuts down.
 java.lang.String getSessionId()
          Returns the session id.
 IOTransport getTransport()
          gets the currently used transport.
 boolean isConnected()
          Checks if IOConnection is currently connected.
 void on(java.lang.String event, IOAcknowledge ack, java.lang.Object... args)
          On [Event].
 void onConnect()
          On connect.
 void onDisconnect()
          On disconnect.
 void onError(SocketIOException socketIOException)
          On error.
 void onMessage(org.json.JSONObject json, IOAcknowledge ack)
          On message.
 void onMessage(java.lang.String data, IOAcknowledge ack)
          On message.
 void reconnect()
          forces a reconnect.
 boolean register(SocketIO socket)
          Connects a socket to the IOConnection.
static IOConnection register(java.lang.String origin, SocketIO socket)
          Creates a new connection or returns the corresponding one.
 void send(SocketIO socket, IOAcknowledge ack, org.json.JSONObject json)
          sends a JSON message from SocketIO to the IOTransport.
 void send(SocketIO socket, IOAcknowledge ack, java.lang.String text)
          sends a String message from SocketIO to the IOTransport.
 void transportConnected()
          Transport connected.
 void transportData(java.lang.String text)
          IOTransport should call this function if it does not support framing.
 void transportDisconnected()
          Transport disconnected.
 void transportError(java.lang.Exception error)
          Transport error.
 void transportMessage(java.lang.String text)
          Transport message.
 void unregister(SocketIO socket)
          Disconnect a socket from the IOConnection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

static final java.util.logging.Logger logger
Debug logger


FRAME_DELIMITER

public static final java.lang.String FRAME_DELIMITER
See Also:
Constant Field Values

SOCKET_IO_1

public static final java.lang.String SOCKET_IO_1
Socket.io path.

See Also:
Constant Field Values

acknowledge

java.util.HashMap<java.lang.Integer,IOAcknowledge> acknowledge
Acknowledges.


DUMMY_CALLBACK

public static final IOCallback DUMMY_CALLBACK
A dummy callback used when IOConnection receives a unexpected message.

Method Detail

register

public static IOConnection register(java.lang.String origin,
                                    SocketIO socket)
Creates a new connection or returns the corresponding one.

Parameters:
origin - the origin
socket - the socket
Returns:
a IOConnection object

error

protected void error(SocketIOException e)
Populates an error to the connected IOCallbacks and shuts down.

Parameters:
e - an exception

register

public boolean register(SocketIO socket)
Connects a socket to the IOConnection.

Parameters:
socket - the socket to be connected
Returns:
true, if successfully registered on this transport, otherwise false.

unregister

public void unregister(SocketIO socket)
Disconnect a socket from the IOConnection. Shuts down this IOConnection if no further connections are available for this IOConnection.

Parameters:
socket - the socket to be shut down

transportConnected

public void transportConnected()
Transport connected. IOTransport calls this when a connection is established.


transportDisconnected

public void transportDisconnected()
Transport disconnected. IOTransport calls this when a connection has been shut down.


transportError

public void transportError(java.lang.Exception error)
Transport error.

Parameters:
error - the error IOTransport calls this, when an exception has occurred and the transport is not usable anymore.

transportData

public void transportData(java.lang.String text)
IOTransport should call this function if it does not support framing. If it does, transportMessage should be used

Parameters:
text - the text

transportMessage

public void transportMessage(java.lang.String text)
Transport message. IOTransport calls this, when a message has been received.

Parameters:
text - the text

reconnect

public void reconnect()
forces a reconnect. This had become useful on some android devices which do not shut down TCP-connections when switching from HSDPA to Wifi


getSessionId

public java.lang.String getSessionId()
Returns the session id. This should be called from a IOTransport

Returns:
the session id to connect to the right Session.

send

public void send(SocketIO socket,
                 IOAcknowledge ack,
                 java.lang.String text)
sends a String message from SocketIO to the IOTransport.

Parameters:
socket - the socket
ack - acknowledge package which can be called from the server
text - the text

send

public void send(SocketIO socket,
                 IOAcknowledge ack,
                 org.json.JSONObject json)
sends a JSON message from SocketIO to the IOTransport.

Parameters:
socket - the socket
ack - acknowledge package which can be called from the server
json - the json

emit

public void emit(SocketIO socket,
                 java.lang.String event,
                 IOAcknowledge ack,
                 java.lang.Object... args)
emits an event from SocketIO to the IOTransport.

Parameters:
socket - the socket
event - the event
ack - acknowledge package which can be called from the server
args - the arguments to be send

isConnected

public boolean isConnected()
Checks if IOConnection is currently connected.

Returns:
true, if is connected

getTransport

public IOTransport getTransport()
gets the currently used transport.

Returns:
currently used transport

onDisconnect

public void onDisconnect()
Description copied from interface: IOCallback
On disconnect. Called when the socket disconnects and there are no further attempts to reconnect

Specified by:
onDisconnect in interface IOCallback

onConnect

public void onConnect()
Description copied from interface: IOCallback
On connect. Called when the socket becomes ready so it is now able to receive data

Specified by:
onConnect in interface IOCallback

onMessage

public void onMessage(java.lang.String data,
                      IOAcknowledge ack)
Description copied from interface: IOCallback
On message. Called when the server sends String data.

Specified by:
onMessage in interface IOCallback
Parameters:
data - the data.
ack - an IOAcknowledge instance, may be null if there's none

onMessage

public void onMessage(org.json.JSONObject json,
                      IOAcknowledge ack)
Description copied from interface: IOCallback
On message. Called when the server sends JSON data.

Specified by:
onMessage in interface IOCallback
Parameters:
json - JSON object sent by server.
ack - an IOAcknowledge instance, may be null if there's none

on

public void on(java.lang.String event,
               IOAcknowledge ack,
               java.lang.Object... args)
Description copied from interface: IOCallback
On [Event]. Called when server emits an event.

Specified by:
on in interface IOCallback
Parameters:
event - Name of the event
ack - an IOAcknowledge instance, may be null if there's none
args - Arguments of the event

onError

public void onError(SocketIOException socketIOException)
Description copied from interface: IOCallback
On error. Called when socket is in an undefined state. No reconnect attempts will be made.

Specified by:
onError in interface IOCallback
Parameters:
socketIOException - the last exception describing the error