2

I have recently discovered HTML 5's support for the WebSocket protocol. I began idly experimenting with it and I decided to undertake a simple chat program project. For it, I'd like to be able write a WebSocket server and have it serve users inside of a blog post, using Google's Blogger website.

The server would be written in Javascript and would have all the code needed to send one person's "conversation line" to all other WebSocket connections connected to it. Later, I may implement "chatrooms" where each line is simply redirected to certain users.

My first question: would it be possible to create a Javascript-based WebSocket server? I've researched a bit, and it seems that all server implementations were in PHP or some server-side language similar to that. Would it be possible to write a WebSocket server with Javascript?

The server implementation would be inside of a webpage, so as long as the blog is up, the server would work as well. My blog can be found here. The client's code would be like this:

server = "http://imdmstromyf8imdcaptomysl.blogspot.com/post_that_handles_chat";
connection = new WebSocket (server);

The problem is, a WebSocket runs on its own protocol (ws:// or wss://), so changing "http://" to "wss://" would not work. Could I tunnel the WebSocket protocol through HTTP? If I did, I would probably have to use Ajax, but avoiding that is the reason I wanted a WebSocket chat program.

Blogger has a place where you can insert your own HTML; would it be possible to use PHP tags to delineate the code from HTML?

I would just like to know whether it's possible to do what I want, and if it is, some implementation tips or (even better) some example code to use.

1
  • 2
    "I've researched a bit, and it seems that all server implementations were in PHP or some server-side language similar to that." -- No way, you didn't find Node.js while searching for websockets? I find that hard to believe...socket.io, and ws are some of the most popular. Commented Jan 25, 2013 at 14:31

1 Answer 1

3
"The server implementation would be inside of a webpage"

A server implementation is not in a web page. Not sure what you meant here. You may want to edit your question.

Node.js is library written in JavaScript for use on the server. Google this and you should find many ways of getting started on running a WebSockets. To connect to the client, you will be using JavaScript as well, which you should again select a library that supports web sockets.

Additionally, you will need to verify the client' Browser supports it.

You can look at browsers that support web sockets here

Here is a jQuery plugin for web sockets

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. What I mean is: would it be possible to have the Blogger.com server host a mini websocket server inside of a blog post? It's like when you load a page --you get HTML, Javascript and CSS. Would it be possible to use the Blogger.com server that gives you the page to also handle WebSocket? My idea is to have a script that uses the blog to deliver the chat to all other websocket connections connected to the server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.