-
Notifications
You must be signed in to change notification settings - Fork 1
/
README
96 lines (79 loc) · 2.52 KB
/
README
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
Intro
==============================================
This provides all the necessary objects to talk to the Thousand Parsec protocol.
Support Libraries
==============================================
For basic Thousand Parsec functionality no extra Python libraries are needed.
It is recommened to install either if you are running a server,
python-pyopenssl
m2crypto
or one of the following if you are running a client,
python-pyopenssl
m2crypto
TLS Lite
Installing these libraries will improve SSL support.
Clients will not be able to connect to TLS enabled Thousand Parsec servers (but
it should be able to connect to SSL3 and SSL2 servers) without one of these
libraries.
Servers will not be able to serve SSL connections (or tunnel HTTPS connections)
without one of these libraries.
Library
==============================================
The library can run in either non-blocking or blocking mode.
In blocking mode operations preformed on the connection will wait for the
results to become available before returning. It will never return None.
In non-blocking mode operations preformed on the connection will return nothing.
The connection must be until the result is obtained. It is safe to preform more
operations on the connection before the connection has returned the result, no
answer will be lost.
Poll will return None until the complete response is available. Poll will return
the answers in the same order that the actions where preformed.
If you want to wait for an action to complete you can use wait which will wait
until the result if ready and return it. Wait will never return None.
Blocking Example Usage:
>>>
>>> import sys
>>>
>>> from tp import netlib
>>>
>>> # Create the object and connect to the server
>>> c = netlib.Connection("127.0.0.1", 6329)
>>> if not c.connect():
>>> print "Could not connect to the server"
>>> sys.exit(1)
>>>
>>> if not c.login("username", "password"):
>>> print "Could not login"
>>> sys.exit(1)
>>>
Non-Blocking Example Usage:
>>>
>>> import sys
>>>
>>> from tp import netlib
>>>
>>> # Create the object and connect to the server
>>> c = netlib.Connection("127.0.0.1", 6329)
>>>
>>> c.connect()
>>> c.login("username", "password")
>>>
>>> # Wait for the connection to be complete
>>> if not c.wait():
>>> print "Could not connect to the server"
>>> sys.exit(1)
>>>
>>> r = c.poll()
>>> while r == None:
>>> r = c.poll()
>>>
>>> # Do some other stuff!
>>> pass
>>>
>>> if not r:
>>> print "Could not login"
>>> sys.exit(1)
>>>
>>> # Disconnect and cleanup
>>> c.disconnect()
>>>