Reputation: 51
I have looked at a a variety of simple tutorials on how make a PHP websocket chat application. I felt this would be a good starting point for looking at websockets. however I seem to be falling at the first hurdle!!
I have tried running a number source code examples but have had no luck.
I have a windows 7 OS and I am attempting to run the websocket server using Wamp.
I have tried running it from the windows command prompt and from the command prompt that comes with wamp.
What should I be entering into these prompts to get the websocket server up and running?
I appreciate this question is pretty vague. But if anyone can shed some light on where I am going wrong, I would be very grateful.
Upvotes: 4
Views: 15868
Reputation: 1101
this php library can be used to setup a very simple php websocket server
https://github.com/ghedipunk/PHP-Websockets
I have tested, it works.
Upvotes: 2
Reputation: 174672
To use websockets, you need to have both browser and a server that support the websocket protocol. You will also need a traditional web server like Apache or IIS to serve your website's static content.
phpws is both a client and server library written in PHP.
Your browser also needs websocket support - which means you are using either Firefox or Chrome (IE doesn't have proper WS support, except in IE10).
Once you have downloaded the websocket server (this is not the same as Apache), you need to run it and make sure its running the background. This means that unless you are using a Windows-native application (like SuperWebSocket), you'll need to make sure not to close the command prompt window!
Once the server is running, you client can connect to it to push messages. This is an example of a client in PHP from the phpws project:
<?php
require_once("websocket.client.php");
$input = "Hello World!";
$msg = WebSocketMessage::create($input);
$client = new WebSocket("ws://127.0.0.1:12345/echo/");
$client->open();
$client->sendMessage($msg);
// Wait for an incoming message
$msg = $client->readMessage();
$client->close();
echo $msg->getData();
?>
Upvotes: 3
Reputation: 1192
I dont know where you went wrong so I just put some tips:
However after while you will find out it's easier to install virtual machine on your Windows an setup Ubuntu on it.
Upvotes: 1
Reputation:
I have no idea how to make a websocket server with PHP, because normally PHP is used for web pages (with HTTP) and not with websockets (different protocol). What I found really easy are websockets with socket.io. This is a library for node.js (a platform to write applications with JavaScript) which has also a client-side script that makes it really easy to use websockets with almost any browser, because it also provides fallbacks like Flash and Ajax polling.
Upvotes: 0