HTML5 php websocket - html

I'm new to HTML 5, websocket. We are trying application like white board.Users who all are logged in that particular session can type their thoughts in white board div. It should display to all users who are logged in that session. So i tried to use Php Websocket. what all are the steps need to follow to run php Websocket on server side. Let me know further clarification.
Thanks,
Dhinesh.B

Find some PHP classes that implement the latest Websocket protocol RFC6455. This is an example implementation that I tested and that is working just fine: https://github.com/esromneb/phpwebsocket . Copy those files to your websocket subfolder (e.g. /websocket)
The steps are:
Run the server side PHP (e.g. php -q websocket.demo.php). Use a previously unused socket port.
Connect to the server using a client HTML with Javascript websocket code. In your Javascript code use the port that you specified for the server (e.g. localhost/websocket/client.html)

Related

How to change path of socket.io in socket.io.slim.js

I am using socket.io for multiuser experience in one of our metaverse projects. We have deployed the code in a https server and after deploying the multiuser experience collapsed. When check for errors, we have found the following error.
enter image description here
enter image description here
we need to change the path of Url for where it needs to look for socket.io.
Can someone suggest any ideas for changing this path?
This usually means one of 2 things:
the socket.io server is not running
the socket.io server is running on a different place
Make sure socket.io is using the HTTPS server, not the HTTP one, and the client is connecting to the correct domain.

Can I use html5 Websockets with windows domain authentication?

Our setup is like this: we use a coldfusion 10 server, and files are on a local intranet. Users use a domain login to access any files over https. I'm interested in using html5 websockets, but the first attempt gave me an error because no credentials were supplied. Is there a way around this? If not, is there a recommended technology for this scenario?
The user does log in on the client side. If it's possible, what I'd really like to do here is pass those credentials when making the connection to the server.
you should be able to supply the authentication header to your web socket server before the elevation to web socket read that and send it back in the headers for the elevation (first frame) then when the browser connects it should have the authentication it needs.
if your using a custom authentication E.G in page not authentication header you can also do this by passing any custom header to your server.
Or mandate that the first thing your web client sends is the authentication details this could be something like {username_hash}.{password_hash} if they don't close the socket to them.
Do not do this.
You're now responsible for sending and encrypting the authentication credentials yourself, bypassing something that already works and is tested.
Anyone can snoop on an unencrypted websocket port. Use HTTPs for an intranet, use stable solutions, don't reinvent this wheel because it tickles your fancy.
In a couple of years some colleague will have to maintain this and will have to figure out how your homebrew version works versus something that's solid like plain browser authentication.
My advice: Leave this to the browser and to well-tested coldfusion libraries.

How to automatically start and keep socket.io instance in server

I have been developing a chat application using socket.io on Ubuntu and it needs to be run manually using the command line prior to test it on browser.
I am a PHP developer and how am I supposed to run the application on the server side without putting hands on the terminal?
Furthermore after executing the .js file via command line, I can test the application typing the host and a port typed on in the address bar. How can I overcome that if I am to embed the chat on a PHP page? Currently it looks like an external application.
The socket.io chat uses a .html page to draw the interface. How can I embed it in a PHP file?
Please help.

Can an extension provide its own location to a native messaging host?

I have an extension that uses native messaging to launch a server. It
sends a message through the native messaging API which launches a host
process; the host process launches an HTTP server on an ephemeral port
and sends the port number back to the extension; the extension then
connects to that port. All of this works fine.
I am attempting to generalize this mechanism in two ways, and cannot
figure out how to do it.
(1) I would like to allow multiple applications to communicate with a
single installed native messaging host. Currently, each application
needs to install its own host which is configured with information
about the application (basically contains all the code for a "server"
for that application). I would like to use a single host which can
serve arbitrary applications.
(2) I would, thus, like to be able to start the process by having the
application connect to the native messaging host and provide it with
the installation directory of the extension. Then I'd like the native
messaging host to be able to read that directory looking for
configuration information, code, etc. so that it can initialize itself
appropriately. Basically, I'd like the native messaging host to be
able to run code and scripts bundled with the extension, in arbitrary
data formats (in my case, probably plain text, JavaScript files, and Java JAR/class
files) to implement the "server" or "native" portion of the
application.
Given that NPAPI plugins are supposed to be re-implemented using the
native messaging API, I am assuming that this is possible and that I
just can't figure out how to do it.
The only approach that I've come up with that might work seems overly
complicated and underperformant -- basically, I believe I could allow
the host to load code from the extension by having the host send a
"request" to the client (by posting a JSON message, with a request ID and a path, say), and having the client use XMLHttpRequest with ArrayBuffer (in the most general case)
to its own chrome-extension:// URL (as obtained by chrome.runtime using the path as the argument to getURL) to
read its files, serializing them back to the host as JSON. Would this
work? Is this the intended approach?

AS3 FTP Programming and the Socket and ByteArray Classes

Sorry for the subject line sounding like an even nerdier Harry Potter title.
I'm trying to use AS3's Socket class to write a simple FTP program to export as an AIR app in Flex Builder 3. I'm using an FTP server on my local network to test the program. I can successfully connect to the server (the easy part) but I can't send any commands. I'm pretty sure that you have to use the ByteArray class to send these commands but there's some crucial piece of information that I'm missing apparently. Does anyone know how to do this? Thanks!
Dave
The FTP protocol predates UTF encoding. Switch to ANSI/ASCII for better results. If you do opt for writeMultiByte instead of writeUTFBytes, be aware that it is buggy in linux. Here's one way around it.
There's another question here where the line ending turns out to be the culprit, so make sure that you get it right (as suggested above).
As said before, if this is running from the web, all socket connections will require a crossdomain policy, but this is NOT file based over HTTP. Recent changes to the security rules mean that any socket based connection must first get a crossdomain from a policy server hosted on port 843 of the target host.
Quoting from Adobe:
A SWF file may no longer make a socket connection to its own domain without a socket policy file. Prior to version 9,0,115,0, a SWF file was permitted to make socket connections to ports 1024 or greater in its own domain without a policy file.
HTTP policy files may no longer be used to authorize socket connections. Prior to version 9,0,115,0, an HTTP policy file, served from the master location of /crossdomain.xml on port 80, could be used to authorize a socket connection to any port 1024 or greater on the same host.
Essentially, what this means is that you must be in control of the target FTP host, and install supplementary software on it to get this working.
Read this link too and maybe it can be useful this one too.
The first one is about policy files and the second is an example of a TELNET (so, no FTP here) client.
I've been able to get an FTP client working in a browser, but it's buggy. I had to get a listener running on port 843 to server the policy file so that Flash would be allowed to connect and transfer data. Then, I had to figure out how FTP actually works:
You have to open 2 sockets: a command socket and a data socket. The command socket is where you send your USER, PASS, CWD, and STOR commands. The data socket is where you write your ByteArray data to. Sending the PASV command will tell you what port your data socket must connect to.
Where it is buggy is on Mac, in both Safari and FF, when I call the "socket.close()" command, the server socket actually closes. On Windoze, it does not. This is a huge problem because the Event.CLOSE event is not fired until the SERVER closes the connection. This is in the livedocs.
This is where I'm at. I have no idea why it would work flawlessly on Mac and then be completely busted in 3 different browsers on Windows. The only thing I can come up with is that it's either something in my Windows configuration that's preventing proper communication with the server, or it's the Window Flash player that's causing the problem.
Any thoughts?
We will need more info to resolve this.. What you're saying here appears correct to me. You're using the Socket class to send data though, not ByteArray.
Are you sure data is not being sent? How are you receiving the response? It may be that it's working fine but you're just not aware of it? As i said, tell us more about what you're doing..
Lee Brimelow has a screencast on gotoAndLearn of writing an POP3 client. It's essentially the same of what you're doing so take a look.
Are you 100% sure the syntax is correct? I know with HTTP you'll have to an include extra linebreak after the request for it to go through. Without it you'll get nothing back. Not sure how it is with FTP though.
The FTP standard requires CRLF at the end of commands. Try using "\r\n" in place of the "\n" in your example.
You must serve the CrossDomain Policy File from your FTP server in order to conect correctly.
From what I've gathered, you have to send each command one at a time and validate the response before moving on. You should be getting something back against ProgressEvent.SOCKET_DATA
Try just this and see what you get in response.
socket.writeUTFBytes("USER "+user+"\n"); socket.flush();
You would then read the response out like this.
var response:String = mySocket.readUTFBytes(mySocket.bytesAvailable);