|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectwebsocket4j.AbstractWebSocket
public abstract class AbstractWebSocket
This class implements common functionality of server and client side web socket.
Field Summary | |
---|---|
protected java.io.InputStream |
in
|
protected java.io.OutputStream |
out
|
protected java.net.Socket |
socket
|
Constructor Summary | |
---|---|
AbstractWebSocket(java.net.Socket socket,
java.lang.Integer timeout,
java.lang.Object... args)
Creates new WebSocket instance using given socket for communication and limiting handshake time to given milliseconds. |
Method Summary | |
---|---|
protected java.lang.String |
byteCollectionToString(java.util.Collection<java.lang.Byte> collection)
Creates a string from given byte collection. |
void |
close()
Closes the connection. |
java.lang.String |
getMessage()
Gets a message form the other party. |
protected abstract void |
handshake(java.lang.Object... args)
Performs an opening handshake. |
boolean |
isClosed()
Checks if this socket is closed. |
protected byte[] |
makeResponseToken(int key1,
int key2,
byte[] token)
Generates response to client's opening handshake challenge. |
protected byte[] |
readBytes(java.lang.Integer count)
Reads given number of bytes from the socket. |
protected java.lang.String |
readLine()
Reads line (terminated by "\r\n") from the socket. |
void |
sendMessage(java.lang.String message)
Sends a message to the other party. |
protected void |
writeLine(java.lang.String line)
Writes given line to socket. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.net.Socket socket
protected java.io.InputStream in
protected java.io.OutputStream out
Constructor Detail |
---|
public AbstractWebSocket(java.net.Socket socket, java.lang.Integer timeout, java.lang.Object... args) throws java.io.IOException
socket
- socket that should be used for communicationtimeout
- maximum time in milliseconds for the handshakeargs
- arguments that will be passed to handshake call
java.io.IOException
- exception thrown when there is communication error or
protocol errorMethod Detail |
---|
protected java.lang.String byteCollectionToString(java.util.Collection<java.lang.Byte> collection)
collection
- collection to be converted
public void close() throws java.io.IOException
java.io.IOException
public java.lang.String getMessage() throws java.io.IOException
java.io.IOException
- thrown when there is a problem with the connection or
protocolprotected abstract void handshake(java.lang.Object... args) throws java.io.IOException, java.security.NoSuchAlgorithmException
java.io.IOException
- thrown when there is a problem in socket communication or
client does not follow the handshake protocol
java.security.NoSuchAlgorithmException
- thrown when JVM doesn't support MD5 algorithmpublic boolean isClosed()
protected byte[] readBytes(java.lang.Integer count) throws java.io.IOException
count
- number of sockets to read
java.io.IOException
- thrown when an error occurs while readingprotected java.lang.String readLine() throws java.io.IOException
java.io.IOException
- thrown when an error occurs while readingpublic void sendMessage(java.lang.String message) throws java.io.IOException
message
- message to be sent
java.io.IOException
- thrown when there is a problem with the connection.protected void writeLine(java.lang.String line) throws java.io.IOException
line
- line to be written
java.io.IOException
- thrown when an error occurs while writingprotected byte[] makeResponseToken(int key1, int key2, byte[] token) throws java.security.NoSuchAlgorithmException
key1
- value of Sec-WebSocket-Key1 fieldkey2
- value of Sec-WebSocket-Key2 fieldtoken
- bytes sent after the fields
java.security.NoSuchAlgorithmException
- thrown if JVM doesn't support MD5 algorithm
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |