File: sockettest.py

package info (click to toggle)
kaa-base 0.6.0%2Bsvn4596-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch, wheezy
  • size: 2,348 kB
  • ctags: 3,068
  • sloc: python: 11,094; ansic: 1,862; makefile: 74
file content (33 lines) | stat: -rw-r--r-- 869 bytes parent folder | download | duplicates (2)
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
import kaa

@kaa.coroutine()
def new_client(client):
    ip, port = client.address
    print 'New connection from %s:%s' % (ip, port)
    #yield client.starttls_server()
    client.write('Hello %s, connecting from port %d\n' % (ip, port))

    remote = tls.TLSSocket()
    #remote = kaa.Socket()
    yield remote.connect('www.freevo.org:80')
    #yield remote.connect('urandom.ca:443')
    #try:
    #    yield remote.starttls_client()
    #except:
    #    print "TLS ERROR"
    #    return

    remote.write('GET / HTTP/1.0\n\n')
    while remote.connected:
        data = yield remote.read()
        yield client.write(data)
    client.write('\n\nBye!\n')
    client.close()

from kaa.net import tls
#server = tls.TLSSocket()
server = kaa.Socket()
server.signals['new-client'].connect(new_client)
server.listen(8080)
print "Connect to localhost:8080"
kaa.main.run()