I have a button "connect" ! when i press that button i want to open a php socket connection to a ip:port and the connection should stay open to send and receive data messages until the users click;s disconnect. how can i do that? i have the following code:
if (isset($_POST['cmd_connect'])) {
// select in baza de date nodes pentru randul selectat de user
$selectOption = $_POST['cmb_select_node'];
$sqlquery = mysql_query("SELECT * FROM `nodes` WHERE node_mac='{$selectOption}'");
if ($sqlquery === FALSE) {
die(mysql_error());
}
while ($row = mysql_fetch_array($sqlquery)) {
$host = $row['node_ip'];
$port = 11000;
};
// don't timeout!
set_time_limit(0);
// Creaza si se connecteaza la socket internet IP
$socket=socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$s_connect=socket_connect($socket, $host, $port);
$timeout= array('sec'=>30,'usec'=>500000);
socket_set_option($socket, SOL_SOCKET , SO_KEEPALIVE, 1);
socket_set_option($socket, SOL_SOCKET , SO_RCVTIMEO,$timeout);
// Conditie creare si connectare socket
if (! $socket) {
?> <script>alert('Could not create the socket to client');</script>
<?php
}
elseif($s_connect) {
?> <script>alert('Your Are now connected');</script>
<?php
}
}
?>
thanks