On Fri, Feb 22, 2008 at 6:40 AM, Nathan <[EMAIL PROTECTED]> wrote: > > On Thu, Feb 21, 2008 at 9:00 AM, Drew Smathers <[EMAIL PROTECTED]> wrote: > > > > On Thu, Feb 21, 2008 at 10:50 AM, Nathan <[EMAIL PROTECTED]> wrote: > > > My initial implementation uses the built-in socket module, but I can't > > > find a way to flush the socket! Any suggestions for a simple way for > > > fast communications, or a way to make sockets work fast? (right now, > > > the sockets seem to just wait about 2 seconds, and then transmit, > > > which is rather funny to watch, but not very playable). > > > > > > > Just use Twisted. Then you might actually come close to the "simple" > > objective. Nonetheless, you might want to google TCP_NODELAY for > > your particular problem. > > Twisted and "simple" have nothing to do with each other in my > experience. I even bought the Twisted book, but I have a really hard > time getting into it (not to mention that the developers seem to live > on the opposite side of the world and have odd attitudes when you > start asking them questions). I really don't want to deal with a > completely separate event loop. I'd also like to avoid external > dependencies where possible. (Right now I only depend on python > itself and pyglet) > > I'm researching the TCP_NODELAY option, which looks promising, but > there's a curious lack of explanation of those types of flags and how > to use the on http://docs.python.org/lib/module-socket.html --- I > suppose they assume you'll come with socket knowledge from C.
The socket module in Python is a direct copy of the C (POSIX) socket API (modulo struct sizes). So they do assume you have socket knowledge from C. If you want low-latency you'll need to use UDP instead of TCP (that is, SOCK_DGRAM instead of SOCK_STREAM). TCP is a reliable two-way communication protocol so packets are guaranteed to reach the other host *in order*. UDP is connectionless and one-way (iirc) TCP is slow because, basically, 2 reasons; 1- Every packet received needs an ACKnowledgement sent back. 2- Nagle's algorithm which delays tiny packets to increase throughput (but increases latency) To use UDP properly you'll need to write a networking layer that can deal with dropped and out-of-order packets. HTH --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pyglet-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en -~----------~----~----~----~------~----~------~--~---
