示例#1
0
    def test_sock_xform(self):

        class Xor(s_socket.SockXform):
            def send(self, byts):
                return xor(0x56,byts)

            def recv(self, byts):
                return xor(0x56,byts)

        lisn = s_socket.listen( ('127.0.0.1',0) )

        sockaddr = lisn.getsockname()

        sock1 = s_socket.connect(sockaddr)
        sock2,addr = lisn.accept()

        sock1.sendall(b'woot')
        self.assertEqual( sock2.recvall(4), b'woot' )

        xform = Xor()
        sock1.addSockXform(xform)
        sock2.addSockXform(xform)

        sock1.sendall(b'woot')
        self.assertEqual( sock2.recvall(4), b'woot' )
示例#2
0
文件: tcp.py 项目: drstrng/synapse
 def _initServerSock(self):
     host = self.link[1].get('host')
     port = self.link[1].get('port')
     sock = s_socket.listen((host, port), relay=self)
     if sock != None:
         self.link[1]['port'] = sock.getsockname()[1]
     return sock
示例#3
0
文件: tcp.py 项目: piggum/synapse
 def _initServerSock(self):
     host = self.link[1].get('host')
     port = self.link[1].get('port')
     sock = s_socket.listen((host,port),relay=self)
     if sock != None:
         self.link[1]['port'] = sock.getsockname()[1]
     return sock
示例#4
0
    def test_sock_xform(self):
        class Xor(s_socket.SockXform):
            def send(self, byts):
                return xor(0x56, byts)

            def recv(self, byts):
                return xor(0x56, byts)

        lisn = s_socket.listen(('127.0.0.1', 0))

        sockaddr = lisn.getsockname()

        sock1 = s_socket.connect(sockaddr)
        sock2, addr = lisn.accept()

        sock1.sendall(b'woot')
        self.assertEqual(sock2.recvall(4), b'woot')

        xform = Xor()
        sock1.addSockXform(xform)
        sock2.addSockXform(xform)

        sock1.sendall(b'woot')
        self.assertEqual(sock2.recvall(4), b'woot')