Skip to content

Commit

Permalink
Update info
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav WEB committed Jun 24, 2014
1 parent 8459394 commit 2886e4b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ You're always can ask me for this module if you have write me [issue](https://gi

3. Go to your shell command-line interface and type: `php -q index.php websocket open`

4. Setup your Client-side script's to communicating with the server .. ws://host:port/websockets/open communicating as similarity

--------------------------------------
In order to start using the module clone the repo in your vendor directory or add it as a submodule if you're already using git for your project:

Expand Down
29 changes: 13 additions & 16 deletions src/WebSockets/Service/WebsocketServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ public function start()
{
// open TCP / IP stream and hang port specified in the config
$this->_connection = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);


//bind socket to specified host
socket_bind($this->_connection, $this->_config['host'], $this->_config['port']);
// reuseable port

socket_set_option($this->_connection, SOL_SOCKET, SO_REUSEADDR, 1);

//bind socket to specified host
socket_bind($this->_connection, 0, $this->_config['port']);

// listen connection Resourse #id
socket_listen($this->_connection);
// listen socket Resourse #id
socket_listen($this->_connection, $this->_config['connections_limit']);

// add Master connection ID
$this->_sockets[] = $this->_connection;
Expand All @@ -80,7 +80,7 @@ public function start()
{
$read = $this->_sockets;
$write = $except = null;
// returns the socket resources in $read socket's array
// $read array will be modified after
socket_select($read, $write, $except, 0, 10);
Expand All @@ -96,13 +96,12 @@ public function start()
socket_getpeername($client, $ip); //get ip address of connected socket

// Create alert browser of the new connection
$response = $this->__mask(json_encode(
[
$response = $this->__mask(json_encode([
'type' => 'system',
'message' => $ip.' connected'
]
)
])
);

$this->__sendMessage($response);

// kill Connect ID used before creating a new connection
Expand All @@ -116,7 +115,7 @@ public function start()
// check all incoming data
while(socket_recv($sock, $buf, 1024, 0) >= 1)
{
$received = $this->__unmask($buf); // decipher the data sent
$received = $this->__unmask($buf); // decipher the data sent
$response_data = (array)json_decode($received);

// data that went into the client
Expand All @@ -135,12 +134,10 @@ public function start()
unset($this->_sockets[$found_socket]);

// Create alert for the clien about disconnection
$response = $this->__mask(json_encode(
[
$response = $this->__mask(json_encode([
'type' => 'system',
'message' => $ip.' disconnected'
]
)
])
);
}
}
Expand Down

0 comments on commit 2886e4b

Please sign in to comment.