from pycotcp.pycotcp import Pyco from pycotcp.pycotcp import DeviceInfo import pycotcp.socket as socket import time ioth = Pyco() device = DeviceInfo().with_type("vde") \ .with_name("vde0") \ .with_path("/tmp/vde.ctl") \ .with_address("fd01:8ec4:cef9:87c1::0003") \ .with_netmask("ffff:ffff:ffff:ffff::") \ .create() ioth.start_handler() serversocket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) serversocket.bind(('::', 8092)) serversocket.listen(16) # become a server socket, maximum 5 connections while True: print "Accepting..." connection, address = serversocket.accept() print "Accept DONE, connection: %s, address: %s" % (connection.name, address) print "Accepted connection from %s" % connection.name buf = connection.recv(64) if len(buf) > 0: print buf break print "Read nothing..." serversocket.shutdown(socket.SHUT_RDWR)
from pycotcp.pycotcp import Pyco from pycotcp.pycotcp import DeviceInfo from pycotcp.fdpicotcpadapter import FDPicoTCPAdapter import pycotcp.socket as socket import time context = FDPicoTCPAdapter() ioth = Pyco(context=context) #device = DeviceInfo(context=context).with_type("vde") \ # .with_name("stotest") \ # .with_path("/tmp/vde.ctl") \ # .with_address("10.40.0.35") \ # .with_netmask("255.255.255.0") \ # .create() time.sleep(2) clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM, context=context) clientsocket.connect(('10.40.0.55', 8092)) print "Sending data..." clientsocket.send('hello') time.sleep(2) clientsocket.close() time.sleep(2)
#!/usr/bin/env python from pycotcp.pycotcp import Pyco from pycotcp.pycotcp import DeviceInfo import pycotcp.socket as socket import time ioth = Pyco() device = DeviceInfo().with_type("vde") \ .with_name("stotest") \ .with_path("/tmp/vde.ctl") \ .with_address("fd01:8ec4:cef9:87c1::0002") \ .with_netmask("ffff:ffff:ffff:ffff::") \ .create() ioth.start_handler() clientsocket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) clientsocket.connect(('fd01:8ec4:cef9:87c1::0003', 8092)) time.sleep(1) count_sent = clientsocket.write('hello world!') #count_sent = clientsocket.send('hello world!') #count_sent = clientsocket.sendall(memoryview("hello world")) #count_sent = clientsocket.sendto('hello world!', ('10.40.0.153', 8092)) print "I sent %d bytes!" % count_sent time.sleep(1) clientsocket.close()
from pycotcp.lwipv6adapter import Lwipv6Adapter import pycotcp.socket as socket import time context = Lwipv6Adapter() ioth = Pyco(context=context) device = DeviceInfo(context=context).with_type("vde") \ .with_name("vde") \ .with_path("/tmp/vde.ctl") \ .with_address("fd01:8ec4:cef9:87c1::0003") \ .with_netmask("ffff:ffff:ffff:ffff::") \ .create() serversocket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM, context=context) serversocket.bind(('::', 8092)) serversocket.listen(5) # become a server socket, maximum 5 connections while True: print "Accepting..." connection, address = serversocket.accept() print "Accepted connection from %s" % connection.name buf = connection.recv(64) if len(buf) > 0: print buf break print "Read nothing..." serversocket.shutdown(socket.SHUT_RDWR)