Friday, June 5, 2015

Testing Websocket Service from Browser

Move aside HTTP, WebSocket is the new kid in the block. So typical request-response cycle initiated always from HTTP clients (like a browser) is gone. Websocket brings in more responsive communication to the web. But, you can't test WebSockets directly from the browser (the way we do for HTTP). This post, I will provide some hacks to simplify your WebSocket development by enabling easier testing.

Does your browser supports WebSocket

Not all browsers support WebSockets, so before testing the service make sure your browser has support for it. One quick way is, ping a WebSocket hosted on the public web from your browser.  How about testing a public WebSocket service from your browser? Launch below URL and just test it out (Make sure you have internet connectivity):


simple, if you are able to ping the service; you have support in your browser!
You can also check your browser support over, here.   

Test a WebSocket service 

You have written a WebSocket service, now how do you know if it's all good and working. You might end up writing a client in your favorite language (Java / JavaScript). This is overhead!

To make testing easier without writing much code we can use browser plugins. Chrome provides a plugin for testing web socket (there might be an equivalent plugin for other browsers as well). Just install the plugin in chrome and you are all set to test your service. Once it's installed you will notice a small icon (ws) next to search text field. 

Click that link and you have a client for testing WebSockets. Enter your WebSocket URL as shown below and open connection. Once the connection is opened you can keep sending messages to the server and receiving the message from the server. I have shown my own WebSocket service named as helloWebSocket. 



That's it!
---
Live WebSocket echo server: http://www.websocket.org/echo.html


No comments:

Post a Comment