Closed argaen closed 9 years ago
How are you connecting with the server? That is, which client package are you using?
I haven't tried to mess with websockets directly in python, but I wonder if you're running into some trouble because the server is actually serving SockJS, which emulates the websocket API (and which will be using a websocket under the hood, ideally). Maybe the solution would be to connect a Python http client up... SockJS should fall back to xhr polling (or whatever) if it can't do websockets, so I'd think you could wire a Tornado httpclient up.
Plus, it looks like you're trying to connect directly to the tornado server. Shouldn't you connect to the Django server, usually running on :8000 in dev mode?
I'm sorry this isn't more helpful, but now I'm curious. I may have to try it too!
Hey! I'm using the websocket-client package. It allows you to work with websockets in Python. By installing this package you also have a tool called wsdump which allows you to connect to websockets so it's easier to test.
As an example of what I'm trying to do, you can check this code which works connecting to a pusher server and is able to subscribe to the channels and register for events.
My idea with this is the same, I'm trying to connect to the swampdragon server as a client with python and register to channel/events. I need this because I want to synchronize 2 databases (I can't go with multidb because tables and structure are different).
I'm trying to connect to the tornado server directly because this is how the swampdragon js client works, I've been browsing the source code of this package and that's what I saw.
As said in the first post, I'm able to connect to the server but it returns a 200 status and then the client closes the connection. I found this which says that it may not be the correct path to connect, but I really have no idea =/... I will digg more on this.
This is an interesting one.
I'm looking in to this now.
I've come to something. I'm not an expert in websockets and 3 days ago there were just "websockets", now I know there is sockjs and socket.io =).
I've been able to send a message to the chat server example with python by using this sockjs python sample client. You just need to change the url is being used and change the message being sent for the correct format which would be: { route: route, verb: verb, args: args}
. Just change the values for the needed ones according to the running example.
Btw, I haven't found any decent python sockjs client. There is this client which I tested first and looks very good but didn't work for me =/.
Okay I have written a client now. It will be in a separate git repo as I am unsure of including it in the main codebase yet as it has no test cases or anything as of now).
It's currently Py3 only so I'll need a few minutes to make it work with both py2 and 3. I also need to write up a README on how to use it.
So far you can:
As soon as I've sorted out the Py2 version and written the README I'll post a link to the repo
Would it be worth in including In The main repos If at the very least for use in integration testing swamp dragon.
On Saturday, January 31, 2015, Jonas Hagstedt notifications@github.com wrote:
Okay I have written a client now. It will be in a separate git repo as I am unsure of including it in the main codebase yet as it has no test cases or anything as of now).
It's currently Py3 only so I'll need a few minutes to make it work with both py2 and 3. I also need to write up a README on how to use it.
So far you can:
- connect
- subscribe
- receive messages
- send messages
- receive channel messages
As soon as I've sorted out the Py2 version and written the README I'll post a link to the repo
— Reply to this email directly or view it on GitHub https://github.com/jonashagstedt/swampdragon/issues/21#issuecomment-72338043 .
That's an interesting idea, to use it for integration testing.
It is very small but it feels quite untested and I can't really write unit tests for something that requires a running instance of an SD server.
It's working for Py2 and 3 now at least. Just have one caveat to work out with it (famous last words) but having a py client for this does open up for some interesting ideas.
I also have no idea about the performance of this.
If no one finds any big issues with it I'll consider adding it to the main repo.
@argaen I'm using https://github.com/liris/websocket-client and it works quite well.
It's done: https://github.com/jonashagstedt/swampdragon-py-client
Let me know if you run into any issues or need any help with it. I know it's a bit sparse. I'll close this issue for now but feel free to keep the comments going.
@jonashagstedt really? I'll check the client tomorrow for database synchronization between two servers.
I did try to connect with websocket client but it didn't like the 200 error code return code, I'm sure I was doing something wrong and that's why I opened this issue =). I'll check the source code to learn more. Thx for all!
I will open the issues in the client repo if I find anything.
Sounds good. Let me know if there are any issues.
If you are using it to sync your databases it might be better to setup database replication though (but I'm guessing you aren't replicating your entire database but rather something else).
Edit: I see from your previous comment that the servers and schemas are different so scrap the replication comment
Yeah.. I had to build a script for the table and field bindings because the destination database was already built and the central one needed a different structure because it's more generic =).
Interesting use! I would love to know if you have any performance issue and how big payloads you are pushing and the frequency.
The footprint will of course be smaller than using web requests. Are you using something like this:
Server A sends data to replicate to Server B If Server B is running SD you can compute the hash on Server B and reply with that in the callback, so Server A will know that all the data was happily received intact etc.
Right now I'm using django-rest-framework (and that's why I was very happy to find issue #11 =)) with periodic pulls and a filter for each table with last_modified date so it only pulls latest modifications (client is the one saving the last update timestamps if everything goes right). With the actual tables I only needed to pull from the central server to the client(server) and the delay in time was not important. But now I need one with almost instant synchronization and that's why I was looking for something like this.
My intention on server b was to run only as a client because the database is unmanaged by Django (there is another program interacting with the data), I only use Django for this synchronization stuff but yeah, the part of answering with a hash sounds interesting. I'll let you know when I have everything working (I may package it up all together if I can make it generic enough so you can sync both from REST or SD).
Is there any manual on how to connect to swampdragon websocket so I can receive notifications from a python client?
Thanks!
EDIT: I'm trying to connect to the server with the websocket python client to 127.0.0.1:9999/data but it returns a 200, I've also tried /data/chat, /data/chat-route, /chat and more combinations but all return a 404. Where do I have to connect? (I'm running the chat example)