Handling Server Messages

Its a hobby of mine.

The Code

def handleServerMsg(server, serverMsg):
  server.setblocking(1)
  msg = ""
  command = ""
  while True:
    msg += server.recv(10).decode("UTF-8")
    command = msg.split("\n")
    while (len(command) > 1):
      readyMsg = command[0]
      msg = "\n".join(command[1:])
      serverMsg.put(readyMsg)
      command = msg.split("\n")

This is a client's personal mailbox. It takes incoming messages from the server (the mail truck) and puts them in the serverMsg queue (remember, this is a bulletin board or to-do list). Later, these messages are translated to actions in timerFired. How fun.

You've probably seen code that looks similar to this already in this tutorial, so feel free to look back if you are confused about specific lines.

results matching ""

    No results matching ""