0

I'm sorry that this is probably a re-post of some description, however I couldn't find a question that gave me the answer I need.

I'm coding a basic chat server in Python, and I can get the clients to interact perfectly, however, the clients will only receive data after they have sent some.

I need the clients to be able to receive data at any point.

Does anyone have an example of some code I could look at to see how this could be done, or just a worded explanation of how to do it?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
QuarterGeekster
  • 65
  • 1
  • 2
  • 8
  • Hi! I think you're talking about polling? You can use some JS to poll every second, or shorter, depending on your needs. Another thing to look into is websockets. There's a bit of discussion here: http://flask.pocoo.org/mailinglist/archive/2011/12/30/websockets/ regarding Flask, but if you do a quick search for "python websockets" you'll be able to gather some more information. – Ryan O'Donnell Feb 17 '14 at 14:09
  • The issue I'd have with polling is I'm using a windows system. From what I understand, Windows doesn't work well with the "select" module – QuarterGeekster Feb 17 '14 at 14:16
  • This sounds somewhat similar to [this question](http://stackoverflow.com/questions/21816533/asyncio-project-what-am-i-missing). Maybe my answer there will help you too. – poke Feb 17 '14 at 14:29
  • @QuarterGeekster that's wrong, select works with sockets on Windows just fine. – kirelagin Feb 17 '14 at 14:33

1 Answers1

1

That's a really long story.

You could start by looking at Python's asynchat. Next, you might consider looking at Twisted.

kirelagin
  • 13,248
  • 2
  • 42
  • 57
  • I'm using python 3.3.3, so Twisted won't work, as that only works with 2.7. Have you got any examples of using asynchat? – QuarterGeekster Feb 17 '14 at 14:29
  • @QuarterGeekster There is an example on asynchat's page (it's not a chat, but an HTTP handler though, but it's pretty clear). Google also gave me this chat example: http://www.grantjenks.com/wiki/random/python_asynchat_chat_example – kirelagin Feb 17 '14 at 14:32