io.socket
Class SocketIO

java.lang.Object
  extended by io.socket.SocketIO

public class SocketIO
extends java.lang.Object

The Class SocketIO.


Constructor Summary
SocketIO()
          Instantiates a new socket.io connection.
SocketIO(java.lang.String url)
          Instantiates a new socket.io connection.
SocketIO(java.lang.String url, IOCallback callback)
          Instantiates a new socket.io object and connects to the given url.
SocketIO(java.lang.String url, java.util.Properties headers)
          Instantiates a new socket.io connection and sets the request headers used while connecting the first time for authorizing.
SocketIO(java.net.URL url)
          Instantiates a new socket.io connection.
SocketIO(java.net.URL url, IOCallback callback)
          Instantiates a new socket.io object and connects to the given url.
 
Method Summary
 SocketIO addHeader(java.lang.String key, java.lang.String value)
          Adds an header to the headers
 void connect(IOCallback callback)
          connects to an already set host.
 void connect(java.lang.String url, IOCallback callback)
          connects to supplied host using callback.
 void connect(java.net.URL url, IOCallback callback)
          connects to supplied host using callback.
 void disconnect()
          Disconnect the socket.
 void emit(java.lang.String event, IOAcknowledge ack, java.lang.Object... args)
          Emits an event to the Socket.IO server.
 void emit(java.lang.String event, java.lang.Object... args)
          Emits an event to the Socket.IO server.
 IOCallback getCallback()
          Gets the callback.
 java.lang.String getHeader(java.lang.String key)
          Returns the header value
 java.util.Properties getHeaders()
          Returns the headers used while handshaking.
 java.lang.String getNamespace()
          Gets the namespace.
 java.lang.String getTransport()
          Returns the name of the used transport
 boolean isConnected()
          Returns, if a connection is established at the moment
 void reconnect()
          Triggers the transport to reconnect.
 void send(IOAcknowledge ack, org.json.JSONObject json)
          Send JSON data to the Socket.io server.
 void send(IOAcknowledge ack, java.lang.String message)
          Send JSON data to the Socket.io server.
 void send(org.json.JSONObject json)
          Send JSON data to the Socket.io server.
 void send(java.lang.String message)
          Send String data to the Socket.io server.
(package private)  void setHeaders(java.util.Properties headers)
          Sets the headers used while handshaking.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketIO

public SocketIO()
Instantiates a new socket.io connection. The object connects after calling connect(URL, IOCallback) or connect(String, IOCallback)


SocketIO

public SocketIO(java.lang.String url)
         throws java.net.MalformedURLException
Instantiates a new socket.io connection. The object connects after calling connect(IOCallback)

Parameters:
url - the url
Throws:
java.net.MalformedURLException - the malformed url exception

SocketIO

public SocketIO(java.lang.String url,
                java.util.Properties headers)
         throws java.net.MalformedURLException
Instantiates a new socket.io connection and sets the request headers used while connecting the first time for authorizing. The object connects after calling connect(IOCallback)

Parameters:
url - the url
headers - the headers used while handshaking
Throws:
java.net.MalformedURLException - the malformed url exception

SocketIO

public SocketIO(java.lang.String url,
                IOCallback callback)
         throws java.net.MalformedURLException
Instantiates a new socket.io object and connects to the given url. Do not call any of the connect() methods afterwards.

Parameters:
url - the url
callback - the callback
Throws:
java.net.MalformedURLException - the malformed url exception

SocketIO

public SocketIO(java.net.URL url,
                IOCallback callback)
Instantiates a new socket.io object and connects to the given url. Do not call any of the connect() methods afterwards.

Parameters:
url - the url
callback - the callback

SocketIO

public SocketIO(java.net.URL url)
Instantiates a new socket.io connection. The object connects after calling connect(IOCallback)

Parameters:
url - the url
Method Detail

connect

public void connect(java.lang.String url,
                    IOCallback callback)
             throws java.net.MalformedURLException
connects to supplied host using callback. Do only use this method if you instantiate SocketIO using SocketIO().

Parameters:
url - the url
callback - the callback
Throws:
java.net.MalformedURLException

connect

public void connect(java.net.URL url,
                    IOCallback callback)
connects to supplied host using callback. Do only use this method if you instantiate SocketIO using SocketIO().

Parameters:
url - the url
callback - the callback

connect

public void connect(IOCallback callback)
connects to an already set host. Do only use this method if you instantiate SocketIO using SocketIO(String) or SocketIO(URL).

Parameters:
callback - the callback

emit

public void emit(java.lang.String event,
                 java.lang.Object... args)
Emits an event to the Socket.IO server. If the connection is not established, the call will be buffered and sent as soon as it is possible.

Parameters:
event - the event name
args - arguments. can be any argument JSONArray.put(Object) can take.

emit

public void emit(java.lang.String event,
                 IOAcknowledge ack,
                 java.lang.Object... args)
Emits an event to the Socket.IO server. If the connection is not established, the call will be buffered and sent as soon as it is possible.

Parameters:
event - the event name
ack - an acknowledge implementation
args - arguments. can be any argument JSONArray.put(Object) can take.

getCallback

public IOCallback getCallback()
Gets the callback. Internally used.

Returns:
the callback

getNamespace

public java.lang.String getNamespace()
Gets the namespace. Internally used.

Returns:
the namespace

send

public void send(org.json.JSONObject json)
Send JSON data to the Socket.io server.

Parameters:
json - the JSON object

send

public void send(IOAcknowledge ack,
                 org.json.JSONObject json)
Send JSON data to the Socket.io server.

Parameters:
ack - an acknowledge implementation
json - the JSON object

send

public void send(java.lang.String message)
Send String data to the Socket.io server.

Parameters:
message - the message String

send

public void send(IOAcknowledge ack,
                 java.lang.String message)
Send JSON data to the Socket.io server.

Parameters:
ack - an acknowledge implementation
message - the message String

disconnect

public void disconnect()
Disconnect the socket.


reconnect

public void reconnect()
Triggers the transport to reconnect. This had become useful on some android devices which do not shut down tcp-connections when switching from HSDPA to Wifi


isConnected

public boolean isConnected()
Returns, if a connection is established at the moment

Returns:
true if a connection is established, false if the transport is not connected or currently connecting

getTransport

public java.lang.String getTransport()
Returns the name of the used transport

Returns:
the name of the currently used transport

getHeaders

public java.util.Properties getHeaders()
Returns the headers used while handshaking. These Properties are not necessarily the ones set by addHeader(String, String) or SocketIO(String, Properties) but the ones used for the handshake.

Returns:
the headers used while handshaking

setHeaders

void setHeaders(java.util.Properties headers)
Sets the headers used while handshaking. Internally used. Use SocketIO(String, Properties) or addHeader(String, String) instead.

Parameters:
headers - the headers used while handshaking

addHeader

public SocketIO addHeader(java.lang.String key,
                          java.lang.String value)
Adds an header to the headers

Returns:
SocketIO.this for daisy chaining.

getHeader

public java.lang.String getHeader(java.lang.String key)
Returns the header value

Returns:
the header value or null if not present