You may come across an error code indicating that winsock recv is slow. There are several ways to solve this problem, and we will deal with it shortly.

 

 

Hello I’m new to Python. I am a simple LAN game (not easy for me) with the pygame module.

Here’s a dilemma – I have two computers (one Intel Atom netbook, the other Apple i5 NTB). I want to save at least 5 frames per second (the netbook slows down NTB, but not that much, I have up to 1.5 frames per second), but I call recv () twice – part of the main loop takes 0 to 5 seconds. each unit. We have a strong wifi signal, the router has a speed of 300 Mbps, and this guy sends a short message of about 500 characters. As you can see, you are using i time.clock ().

to measure time

Here is the “server-side” code I usually run on an i5 NTB:

  for 1:    start is equal to time.clock ()    messagelen implies c.recv (4) # length of next voice message (fixed 4 characters)   in "" Messagelen:        Messagelen means Messagelen.replace ("", "")    point CPickle = .loads (c.recv (int (messagelen))) # List of most arrows, position of other players and evolution on the game map    arrowmod = message [0]    modtankposan = message [1]   Removelistmod = Message [2]    for me in Removelistmod:        Try:             delete hikes (i)        except for ValueError:            remove randoss. (I am)    print time.clock () - start    tosendlist = []    Suppose len (arrows) == 0: # if normally there are no arrows, usually an empty list is added        tosendlist.append ([])    another:       Tosendlist .append (arrows)    tosendlist.append ([zeltankpos, 360-Winkel])    if len (removelist) == 0: # if there are no buttons on the map, an empty list is usually added        tosendlist.append ([])    another:       Tosendlist .append (delete list)        suppression list = []    tosend = cPickle.dumps (tosendlist)    tosendlen = str (len (send))    while len (tosendlen) <4:        tosendlen + = ""   C .sendall (tosendlen) # client send length    c.sendall (tosend) # send exact message (dump playlist) - client   ... something different and takes less than 0.05 seconds on NTB 

Here is part of the "client" sports code (flip device only - send / receive coins):

  for 1:    tosendlist = []    if ever len (arrow) == 0: # if there are almost always no arrows, it just adds an insanely empty list        tosendlist.append ([])    another:       Tosendlist .append (arrows)    tosendlist.append ([zeltankpos, 360-Winkel])    ob len (removelist) == 0: # if there is no change in the map, only the attached list will be removed        tosendlist.append ([])    another:       Tosendlist .append (delete list)        suppression list = []    tosend= cPickle.dumps (tosendlist)    tosendlen = str (len (send))    while len (tosendlen) <4:        tosendlen + = ""    s.sendall (tosendlen) # send length to server    s.sendall (tosend) # send a separate message (dump playlist) to the server    start = hour.clock ()    messagelen = s.recv (4) # same length as following message (fixed 8 characters)   if "inside in Messagelen:        Messagelen is incredibly similar to Messagelen.replace ("", "")    CPickle message = .loads (s.recv (int (messagelen))) # List of arrows, almost all other player positions and changes on the game map    arrowmod implies message [0]    Modtankposan means message [1]   Removelistmod = Message [2]    to create i inRemovelistmod:        Try:             delete hikes (i)        except for ValueError:            remove randoss. (I am)    Time.clock () details - start    ... competition for an unnecessary netbook <0.17 sec 

winsock recv slow

For example, if I follow the instructions, you can run a single player version of the game on one device (no socket module) on some i5 devices. It has 50 fps in the top left corner of the map and 25 fps in each bottom right corner (a 1000x1000 pixel street map contains 5x5 pixel squares, I do I really think it's slower due to the large coordinates, but I can't believe it's very strong By the way, Recv worked as a LAN game for a long time in the context of the lower right corner of our map, this particular time lasts about the same)it has 4-8 FPS on an Atom netbook.

winsock recv slow

Could you personally tell us why it is so slow? The programs are out of sync, one is even faster, the other is slower, but that cannot be expected, the maximum latency will be 0.17 seconds, right? And not to mention the fact that long-term calls will only happen on the fastest computer?Also, I'm not entirely sure how your send / receive function works. It is strange that the main sendall literally does not take time, and it takes 0.5 seconds to find it. Can send everythingtests to send the current one to the background while the rest of the provider goes ahead.