hi guys
i want to use php websockets... i made a web socket but it didnt work
i hope you guys know some javascript couz the client page is made with javascript and html5

this is the server's code:

$host = "";
$port = 8000;
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Cant create the socket");
if($socket){echo $socket."\n\n"; }
$result = socket_bind($socket, $host, $port) or die("cant bind the socket into the port and the host");
if($result){echo $result."\n\n"; }
$result = socket_listen($socket, 3) or die("cant listen through the socket");
if($result){echo $result."\n\n"; }
$spawn = socket_accept($socket)or die("cant accept the incoming connections\n\n");
if($spawn){echo "an incoming connection\n\n".$spawn; } 
$input = socket_read($spawn, 1024) or die("cant read through the socket\n\n");
if($input){echo  $input."\n\n"; }
$output = strrev($input);
socket_write($spawn, $output, strlen($output)+2) or die("cant write on socket");

and this is the client's page:::

<!DOCTYPE html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	if(!("WebSocket" in window)){
		$('#chatLog, input, button, #examples').fadeOut("fast");	
		$('<p>Oh no, you need a browser that supports WebSockets. How about <a href="http://www.google.com/chrome">Google Chrome</a>?</p>').appendTo('#container');		
		//The user has WebSockets
	function connect(){
			var socket;
			var host = "ws://localhost:8000/socket/my/server.php";
				var socket = new WebSocket(host);
				message('<p class="event">Socket Status: '+socket.readyState);
				socket.onopen = function(){
					message('<p class="event">Socket Status: '+socket.readyState+' (open)');	
				socket.onmessage = function(msg){
					message('<p class="message">Received: '+msg.data);					
				socket.onclose = function(){
					message('<p class="event">Socket Status: '+socket.readyState+' (Closed)');
			} catch(exception){
			function send(){
				var text = $('#text').val();
					message('<p class="warning">Please enter a message');
					return ;	
					message('<p class="event">Sent: '+text)
				} catch(exception){
					message('<p class="warning">');
			function message(msg){
			}//End message()
			$('#text').keypress(function(event) {
					  if (event.keyCode == '13') {

	}//End connect()
<meta charset=utf-8 />
<style type="text/css">
body{font-family:Arial, Helvetica, sans-serif;}
	border:5px solid grey;
	margin:0 auto;
	border:1px solid black;	
#chatLog p{margin:0;}
<title>WebSockets Client</title>

  <div id="wrapper">
  	<div id="container">
    	<h1>WebSockets Client</h1>
        <div id="chatLog">
        <p id="examples">e.g. try 'hi', 'name', 'age', 'today'</p>
    	<input id="text" type="text" />
        <button id="disconnect">Disconnect</button>


but when i run the server using the shell with the current code:

php htdocs\socket\my\server.php -q

and i run the client's code, the output is nothing.. please run the code and see the output and tell me how to solve this problem... i really need to get a solution for it...

i need it for my school's science fair...

any help will be highly appreciated!!

hey guys, come on!!! no one within the whole 900,000 member knows the answer of this problem???? anyway, i am still waiting for your help and i am also still trying to solve it my self

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.