File: client.py

package info (click to toggle)
fibranet 10-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny, squeeze, wheezy
  • size: 140 kB
  • ctags: 233
  • sloc: python: 1,031; makefile: 3
file content (37 lines) | stat: -rw-r--r-- 1,263 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import pygame
import nanothreads
import nanotubes
import time


def main():
    pygame.init()
    #create a client connection to the server on port 1984 using the MessageProtocol
    client = nanotubes.Connector(('10.1.1.55',1984), nanotubes.MessageProtocol)
    screen = pygame.display.set_mode((320,200))

    while True:
        time.sleep(0.01)
        #itereate the network queue
        nanotubes.SocketHandler.poll()
        for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    raise SystemExit
                elif event.type == pygame.MOUSEMOTION:
                    #send all MOUSEMOTION events to the server
                    client.protocol.post(event.type, **event.dict)
        
        #any events recieved from the server are stored in client.protocol.messages
        for event_type, args in client.protocol.messages:
            if event_type == pygame.MOUSEMOTION:
                #draw all MOUSEMOTION events as pixels to the screen
                screen.set_at(args['pos'], (255,255,255))
        
        #clear the incoming network event queue
        client.protocol.messages[:] = []
        pygame.display.flip()
        yield None
        

nanothreads.install(main())
nanothreads.loop()