Note that there are some explanatory texts on larger screens.

plurals
  1. POPython server and Game Client: Message overload?
    primarykey
    data
    text
    <p>I'm writing a game server in Python and a game client in Game Maker with the Faucet Networking plugin (though that shouldn't matter). The client sends an UPDATEXY message to the server each time the player moves, and there is a message chatting thing in the client. With 2 clients connected to the server, it seems that the client gets overloaded with messages (further into the run time, chat messages appear slower and the player lags behind where the actual other player is). I believe this is because the client cannot process the messages at the rate they are flowing in, so I implemented a feature in the client where it would just dump all messages in the receive buffer, and ignore them. This seemed to work, but the player would jerk around violently. Is there any sort of 'clean fix' to this problem, or is it a fundamental thing that I have done wrong since the start? </p> <p>By the way, the protocol I am using is TCP. Is this a problem with TCP itself or am I just using it wrong? Would switching to UDP help?</p> <p>Thanks.</p> <p>EDIT: Code was requested so here you go for the server:</p> <pre><code>def sendmsg(msgtype, msg, conn, args=None): if msgtype == MSG_PLAYER_ASSIGN_ID: dataload = struct.pack('!hhh', MSG_STARTBYTE, msgtype, msg) conn.send(dataload) elif msgtype == MSG_PLAYER_UPDATEXY: #This will only ever be broadcasted #print("Sending xy from " + str(args['pid'])) dataload = struct.pack('!hhhhh', MSG_STARTBYTE, msgtype, args['pid'], msg[0], msg[1]) conn.send(dataload) elif msgtype == MSG_ASKFORLIST: players = msg for player in players: if args['pid'] != player.pid and player.dead == False: dataload = struct.pack('!hhhh' + str(len(str(player.name))) + "s", MSG_STARTBYTE, MSG_PLAYERENTRY, player.pid, len(str(player.name)), player.name.encode()) conn.send(dataload) loginfo("Sent a player") </code></pre> <p>^That's just a few packets, there are more, but they are all pretty much like those</p> <p>Here you go for the client:</p> <pre><code>if msgtype == MSG_PLAYER_UPDATEXY { if tcp_receive(serversocket, 6){ pidtoupdate = read_short(serversocket) //show_message(string(pidtoupdate)) if objNewNetProcessor.pid != pidtoupdate { xtoupdate = read_short(serversocket) ytoupdate = read_short(serversocket) playertoupdate = ds_map_find_value(global.players, string(pidtoupdate)) if playertoupdate != objChar { playertoupdate.y = ytoupdate playertoupdate.x = xtoupdate} }}} if msgtype == MSG_CHAT { if tcp_receive(serversocket, 4){ fromperson = read_short(objNewNetProcessor.serversocket) strlen = read_short(objNewNetProcessor.serversocket) tcp_receive(objNewNetProcessor.serversocket, strlen) chatmsg = read_string(objNewNetProcessor.serversocket, strlen) display_chat(fromperson, chatmsg) }} </code></pre> <p>^Sorry that's a total messtastic, it's just temporary code for now. It too is just a few packets, it handles more below that code, though they all look similar to those.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload