Changeset 42 for python


Ignore:
Timestamp:
11/15/07 15:47:56 (12 years ago)
Author:
sgk
Message:

echoサーバ

Location:
python/stackless
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • python/stackless/udp_server.py

    r41 r42  
    1111  while True: 
    1212    (data, address) = sock.recvfrom(8192) 
    13     stackless.tasklet(handler)(data, address) 
     13    stackless.tasklet(handler)(sock, data, address) 
    1414 
    15 def udp_handler(data, address): 
    16   id = '%08x' % (hash(stackless.current) & 0xffffffff) 
    17   print '%s: received data len=%d from %s' % (id, len(data), address) 
    18   print '  %r' % data 
    19   # XXX なんか処理をする。 
    20   stackless.schedule() 
    21   print '%s: leaving handler' % id 
     15def udp_handler(sock, data, address): 
     16  import time 
     17  print time.time(), '%r' % data 
     18  sock.sendto(data, address)    # エコーバック 
     19  #XXX 時間がかかる処理を行う場合は、適宜の次の行をはさむ。 
     20  # stackless.schedule() 
    2221 
    2322def test(): 
Note: See TracChangeset for help on using the changeset viewer.