Websocket library for python - python

Hi I need a websocket server in python which supports the protocol used in chrome 16(protocol version 13). Tornado and twisted are not working. Websockify works but i can't find any documentation for it. I need minimal setup means lesser imports. Please help me out here thanks in advance.

Maybe you could take a look to pywebsocket, it claims to support protocol version 13 and is designed for :
The pywebsocket project aims to provide a WebSocket standalone server
and a WebSocket extension for Apache HTTP Server, mod_pywebsocket.
Autobahn is another implementation of websockets :
Autobahn WebSockets for Python provides an implementation of the
WebSockets protocol which can be used to build WebSockets clients and
servers
ws4py : Websocket for python :
Python library providing support for the WebSocket protocol defined in
RFC 6455

Here are some examples of implementing a websocket server in Python. Be sure to read and apply the comments on the code of the following examples, because there may be some bugs:
http://popdevelop.com/2010/03/a-minimal-python-websocket-server/ : It has been tested on Chrome, according to the author of the code.
http://mumrah.net/websockets-in-python : At the end of this blog page, the author has included the URL to a Python implementation of a websocket server.
http://dev.enekoalonso.com/2010/05/22/more-websockets-now-with-python/: only works on Chrome, according to the author.

This page contains an implementation of a Python websocket server that can be used through imports:
https://github.com/AdrianGaudebert/python-websocket-server
You should know that the license for using this is MIT. It may only work with Python 3.0.

WebSocket Echo example works on Chrome/16.0.912.63.
It uses txWS a simple library for adding WebSockets server support to your favorite Twisted applications.

If you are still interested in using websockify, there is a simple example of using it to build an echo server included](https://github.com/kanaka/websockify/blob/master/tests/echo.py).
You can run it like this (from a websockify checkout):
./tests/echo.py 8080
The browse to localhost:8080/tests/echo.html. Enter localhost, 8080 for the WebSocket host and port and hit connect. You should see the client sending messages and the server echoing them back (with a "You said: " prefix).

Related

PythonAnywhere - Are sockets allowed?

I have a beginner PythonAnywhere account, which, the account comparison page notes, have "Access to External Internet Sites: Specific Sites via HTTP(S) Only."
So I know only certain hosts can be accessed through HTTP protocols, but are there restrictions on use of the socket module? In particular, can I set up a Python server using socket?
PythonAnywhere dev here. Short answer: you can't run a socket server on PythonAnywhere, no.
Longer answer: the socket module is supported, and from paid accounts you can use it for outbound connections just like you could on your normal machine. On a free account, you could also create a socket connection to the proxy server that handles free accounts' Internet access, and then use the HTTP protocol to request a whitelisted site from it (though that would be hard work, and it would be easier to use requests or something like that).
What you can't do on PythonAnywhere is run a socket server that can be accessed from outside our system.
Nope. PythonAnywhere doesn't support the socket module.

Is it possible to receive GCM messages in python

Using Java one would implement a BroadcastReceiver to use the "Google Cloud Messaging API for Android" and receive GCM multicast messages.
Can the same be achieved with Python (on a PC)? How?
Alternatively is is possible to get the messages on a PC running Ubuntu? (without using Chrome / the PC is a client / server is GAE)
My answer is for GCM implementations. If you are planning a server-and-client setup where the PC is the server (the clients will always be Android devices), you can still receive GCM messages. Instead of downstream messaging (server to client app), it would be upstream (client app to server). To do this, you would need to implement an XMPP setup. There is a Python sample at the bottom of that page.

Host a Python based Websocket server

I am looking to host a basic Websocket server.
The code I want to see running is : FastFlicker
Do you know how and where I can host this application online?
PythonAnywhere dev here. Unfortunate we can't host websocket-based apps on our site right now. The toggle you spotted enables/disables websockets for our in-browser consoles, it's not related to running your own websocket server.
I've added an upvote for websockets to our own issue tracker, but for now you'll have to use a different service :-(
Your solution is OpenShift, even with the free plan you can host FastFlicker.
Click Add Application, choose the good cartridges (Python 2.7).
Then use your gitHub repo url to get the source.
Once the application is running, you need to SSH it to change the address and the port (see this Post).
To be able to ssh you need first to generate a ssh key and to add it in setting on the website
Ok, now kill all processes that uses your port. (lsof -i :8080)
Start your application and now it's working!
(It is in app-deployments/current/repo/ for me, then python FastFlicker.py &)
It is currently hosted here : ws://main-fastflicker.rhcloud.com:8000/
And to test it, you know you can use this generic client..

Http client with get request

Quick question: need pure python script of simple http client without using libs (only socket library possible).
Main task of this client is connect to server, receive greetings, sends get requests and read responses. Also it's good if this code will be compatible with Cython compiler.
I would recommend you using requests https://github.com/kennethreitz/requests package.
But your question looks like an assignment which shall teach you how is http working on TCP communication level. In such case I would recommend you
learn using http protocol over telnet or netcat
then learn TCP communication by Python and repeat, what you already know by telnet

Websockets for client/server communication in chrome packaged app

I have thoroughly looked at the Chrome packaged app website and sample apps but I couldn't find any example related to websockets implementation in an app. I was wondering if there is any example or sample app that uses Websocket for client/server communication in Chrome app? If not then is there any guide? Is it even possible to use WebSocket? I am using Apache HTTP as my server which is in Python.
I'm assuming you're asking about implementing a WebSocket server, because the browser natively supports the client. (Though if you wanted, you could definitely implement the WebSocket client because you have access to the raw TCP interface.)
The Chrome Apps has published a sample WebSocket chat server that servers HTTP requests to load the chat client and uses WebSockets to send messages between clients.
If you look through the implementation, you see it uses the older chrome.socket API to listen to a TCP socket and respond with the correct WebSocket HTTP headers. It does all the bit manipulation to send and receive frames of data as required by the WebSocket spec.

Categories