Initial import to Tizen
[profile/ivi/python-twisted.git] / doc / core / howto / listings / sendmsg / send_replacement.py
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 Demonstration of sending bytes over a TCP connection using sendmsg.
6 """
7
8 from socket import socketpair
9
10 from twisted.python.sendmsg import send1msg, recv1msg
11
12 def main():
13     foo, bar = socketpair()
14     sent = send1msg(foo.fileno(), "Hello, world")
15     print "Sent", sent, "bytes"
16     (received, flags, ancillary) = recv1msg(bar.fileno(), 1024)
17     print "Received", repr(received)
18     print "Extra stuff, boring in this case", flags, ancillary
19
20 if __name__ == '__main__':
21     main()