From caf3f7f84b32f39a25c8f9d42f6c11499fc45021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Obr=C3=A1til?= Date: Sat, 3 Jan 2015 09:44:55 +0100 Subject: [PATCH] Update README.md --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 78416cb..bd9773e 100644 --- a/README.md +++ b/README.md @@ -80,9 +80,17 @@ Invoked when some error occurs during connection. ### Properties #### `state: Socket.State` -Represents state of the socket. It can have three values represented by `Socket.State` enum: `Socket.State.CLOSED`, `Socket.State.OPENING` or `Socket.State.OPENED`. +Provides state of the socket. It can have 4 values represented by `Socket.State` enum: `Socket.State.CLOSED`, `Socket.State.OPENING`, `Socket.State.OPENED` or `Socket.State.CLOSING`. -Initial state of socket is CLOSED. After open is called, it switches to OPENING. If it is successfuly opened, it goes to OPENED state. If opening fails, it goes back to CLOSE. When socket is closed (by the server or by calling close method), it goes to CLOSED as well. +Initial state of socket is CLOSED. Invoking `open` method changes state to OPENING. If it's successfuly opened, it goes to OPENED state. If opening fails, it goes back to CLOSED. Socket goes to CLOSING state immediately after `close` method is called. When socket is closed (by the server or by calling close method), it goes to CLOSED state. + +##### Example +Check if socket is connected: +``` +if (socket.state == Socket.State.OPENED) { + console.log("Socket is opened"); +} +``` ### Methods #### `open(host, port, onSuccess?, onError?): void`