コード例 #1
0
ファイル: VMSTelnet.py プロジェクト: goodeveryone/awsl
    def __init__ (self,
        host = None,
        port = 23,
        readCallback = None,
        stateCallback = None,
    ):
        """Create a telnet connection.

        Inputs:
            readCallback: function to call whenever a line of data is read;
                it will be sent one argument: the line of data
            stateCallback: function to call whenever the socket
                connects or disconnected; it will be sent two arguments:
                    is connected flag (true if connected, false if not)
                    this connection object      
        """
        TCPConnection.__init__(self,
            host=host,
            port=port,
            readCallback=readCallback,
            stateCallback=stateCallback,
            readLines = True,
            authReadCallback = self._authRead,
            authReadLines = False,
        )
        
        self._initData()
コード例 #2
0
ファイル: DataSet.py プロジェクト: tartaruszen/codaspy19
def getTrace(visit_file, direction=None):
    with open(visit_file, 'r') as f:
        sample = json.load(f)

    Config.hostname.update(sample[u'ip_to_name'])
    webId, traceId = sample['visit_log'][u'current_url'], sample['visit_log']['visit_id']
    
    trace = Trace(traceId, webId)
    for tcp_conn in sample['tcp_connections']:
        
        connection_id = tcp_conn['connection_id']
        
        TCP = TCPConnection(connection_id, webId, hostip=sample['visit_log'][u'host_ip'])

        for pkt in tcp_conn['packets']:
            pkt_time, pkt_size = pkt[0], abs(pkt[1])
            
            if pkt_size == 0:
                continue

            pkt_dir = Packet.Outgoing if pkt[1] < 0 else Packet.Incoming

            if direction is None or direction == pkt_dir:
                TCP.addPacket(Packet(pkt_time, pkt_size, pkt_dir))
        TCP._packets.sort(key=lambda x: x.getTime())
        trace.addTcpCon(TCP)
    
    return trace
コード例 #3
0
ファイル: HubConnection.py プロジェクト: r-owen/RO
    def __init__ (self,
        host = None,
        port = 9877,
        readCallback = None,
        stateCallback = None,
        loginExtra = None,
        name = "",
    ):
        """Create a hub connection, but do not connect

        Inputs:
        - host: default TCP address of host (can override when connecting)
        - port: default TCP port (can override when connecting);
            defaults to 9877, the standard hub port
        - readCallback: function to call whenever a line of data is read;
          it will be sent two arguments: (self, readData);
          the read data does not include the line terminator
        - stateCallback: function to call whenever the state of the connection changes;
          it will be sent one argument: self
        - loginExtra: additional string to be sent with the login command.
        """
        TCPConnection.__init__(self,
            host=host,
            port=port,
            readCallback = readCallback,
            readLines = True,
            stateCallback = stateCallback,
            authReadCallback = self._authRead,
            authReadLines = True,
            name = name,
        )
        self._initData()
        self._loginExtra = loginExtra
コード例 #4
0
ファイル: HubConnection.py プロジェクト: goodeveryone/awsl
    def __init__(
        self,
        host=None,
        port=9877,
        readCallback=None,
        stateCallback=None,
        loginExtra=None,
        name="",
    ):
        """Create a hub connection, but do not connect

        Inputs:
        - host: default TCP address of host (can override when connecting)
        - port: default TCP port (can override when connecting);
            defaults to 9877, the standard hub port
        - readCallback: function to call whenever a line of data is read;
          it will be sent two arguments: (self, readData);
          the read data does not include the line terminator
        - stateCallback: function to call whenever the state of the connection changes;
          it will be sent one argument: self
        - loginExtra: additional string to be sent with the login command.
        """
        TCPConnection.__init__(
            self,
            host=host,
            port=port,
            readCallback=readCallback,
            readLines=True,
            stateCallback=stateCallback,
            authReadCallback=self._authRead,
            authReadLines=True,
            name=name,
        )
        self._initData()
        self._loginExtra = loginExtra
コード例 #5
0
ファイル: Test.py プロジェクト: goagile/gof
class Test(unittest.TestCase):
    def setUp(self):
        self.tcp = TCPConnection()

    def test_init_TCPConnection(self):
        self.assertTrue(isinstance(self.tcp.state, TCPClosed))

    def test_change_state(self):
        self.tcp.change_state(TCPEstablished())
        self.assertTrue(isinstance(self.tcp.state, TCPEstablished))

    def test_open(self):
        self.tcp.open()
        self.assertTrue(isinstance(self.tcp.state, TCPEstablished))
コード例 #6
0
ファイル: Test.py プロジェクト: khardi/design_patterns
class Test(unittest.TestCase):

    def setUp(self):
        self.tcp = TCPConnection()

    def test_init_TCPConnection(self):
        self.assertTrue(isinstance(self.tcp.state, TCPClosed))

    def test_change_state(self):
        self.tcp.change_state(TCPEstablished())
        self.assertTrue(isinstance(self.tcp.state, TCPEstablished))

    def test_open(self):
        self.tcp.open()
        self.assertTrue(isinstance(self.tcp.state, TCPEstablished))        
コード例 #7
0
ファイル: VMSTelnet.py プロジェクト: goodeveryone/awsl
    def connect (self,
        username,
        password,
        host = None,
        port = None,
    ):
        """Open the connection and log in.

        Inputs:
            host: IP address (name or numeric) of host
            username: username for login
            password: password for login
        """
        self._initData()
        self._password = password
        self._username = username

        TCPConnection.connect(self, host, port)
コード例 #8
0
ファイル: HubConnection.py プロジェクト: r-owen/RO
 def connect (self,
     progID,
     password,
     username,
     host = None,
     port = None,
 ):
     """Opens the connection and logs in.
     Inputs:
     - progID: the desired program ID; the actual program ID
         should be the same except case may differ
     - password: the password associated with the program ID
     - username: desired username; the actual username should match if unique,
         else the hub will modify it in some fashion
     - host: TCP address of host; overrides the default specified at instantiation
     - port: TCP port of host; overrides the default specified at instantiation
     """
     # make the basic connection
     self._initData()
     self.desProgID = progID
     self.__password = password
     self.desUsername = username
     TCPConnection.connect(self, host, port)
コード例 #9
0
ファイル: HubConnection.py プロジェクト: goodeveryone/awsl
 def connect(
     self,
     progID,
     password,
     username,
     host=None,
     port=None,
 ):
     """Opens the connection and logs in.
     Inputs:
     - progID: the desired program ID; the actual program ID
         should be the same except case may differ
     - password: the password associated with the program ID
     - username: desired username; the actual username should match if unique,
         else the hub will modify it in some fashion
     - host: TCP address of host; overrides the default specified at instantiation
     - port: TCP port of host; overrides the default specified at instantiation
     """
     # make the basic connection
     self._initData()
     self.desProgID = progID
     self.__password = password
     self.desUsername = username
     TCPConnection.connect(self, host, port)
コード例 #10
0
ファイル: TestTCP.py プロジェクト: sharst/PythonBluetooth
class RelayStation():
    def __init__(self):
        self.conn = TCPConnection(self.callback)
    
    def connect(self):    
        self.conn.createServer(port = 4000)
        
    def close_conn(self):
        self.conn.closeConnection()

    def callback(self, pck):
        print "Received new packet: " + repr(pck.read_float_list())
        raw_input()
        out = Packet()
        out.put_float_list(pck.read_float_list())
        print "Sending packet back "
        self.conn.sendPacket(out)
        print "Done."
コード例 #11
0
ファイル: TestTCP.py プロジェクト: sharst/PythonBluetooth
class SendingStation():
    def __init__(self):
        self.conn = TCPConnection(self.callback)
    
    def connect(self):    
        address = "192.168.235.6"
        self.conn.createClient(address, 5000)
        while True:
            pck = Packet()
            dat = [random.random() for _ in range(10)]
            pck.put_float_list(dat)
            print "Sending: " + repr(dat)
            self.conn.sendPacket(pck)
            raw_input()
        
    def close_conn(self):
        self.conn.closeConnection()

    def callback(self, pck):
        print "Received!"
        print "Received new packet: " + repr(pck.read_float_list())
コード例 #12
0
ファイル: TestTCP.py プロジェクト: sharst/PythonBluetooth
 def __init__(self):
     self.conn = TCPConnection(self.callback)
コード例 #13
0
ファイル: HubConnection.py プロジェクト: r-owen/RO
 def _setState(self, newState, reason=None):
     # print "%s._setState(newState=%s, reason=%s)" % (self, newState, reason)
     TCPConnection._setState(self, newState=newState, reason=reason)
     if self._state == self.Authorizing and not self._didStartAuth:
         self._didStartAuth = True
         self.writeLine("1 auth knockKnock")
コード例 #14
0
ファイル: chat_client.py プロジェクト: Orezsub/Kyrsach-KSIS
    import sys
    import socket as ss
    import threading
    import time
    from UDPConnection import UDPConnection
    from TCPConnection import TCPConnection
    from AudioClient import AudioSocketClient
    from VideoClient import VideoSocket
    from time import gmtime, strftime
    from playsound import playsound

    app = QtWidgets.QApplication(sys.argv)
    application = MainWindow()
    application.show()

    TCP_socket = TCPConnection(application.signal.new_message)
    application.set_TCP_socket(TCP_socket)

    # audio_socket = AudioSocketClient()
    # application.set_audio_socket(audio_socket)

    application.ui.Btn_Find_Server.clicked.connect(application.find_server)
    application.ui.Btn_Log_In.clicked.connect(application.log_in)
    application.ui.Btn_Send_Message.clicked.connect(
        application.prepare_and_send_message)
    application.ui.Btn_Log_Out.clicked.connect(application.log_out)
    application.ui.Btn_History_Request.clicked.connect(
        application.history_request)
    application.ui.Btn_Call.clicked.connect(
        application.call_recipient_button_click)
    application.ui.Btn_Mute_Mic.clicked.connect(
コード例 #15
0
ファイル: Test.py プロジェクト: goagile/gof
 def setUp(self):
     self.tcp = TCPConnection()
コード例 #16
0
ファイル: Test.py プロジェクト: khardi/design_patterns
 def setUp(self):
     self.tcp = TCPConnection()
コード例 #17
0
    from UDPConnection import UDPConnection
    from TCPConnection import TCPConnection
    from AudioServer import AudioSocketServer

    HOST = socket.gethostbyname(socket.gethostname())
    PORT = 50007
    LISTEN_ALL_HOST = '0.0.0.0'

    app = QtWidgets.QApplication(sys.argv)
    application = MainWindow()
    application.show()

    UDP_socket = UDPConnection(HOST, PORT)
    UDP_socket.setsockopt_reuseaddr()
    UDP_socket.bind(LISTEN_ALL_HOST, PORT)
    UDP_socket.send_address_to_sender()
    UDP_socket.start_UDP_receiving()

    TCP_socket = TCPConnection(application.signal.new_mes)
    TCP_socket.setsockopt_reuseaddr()
    TCP_socket.bind(HOST, PORT)
    TCP_socket.listen(10)
    TCP_socket.set_server_socket()

    application.set_socket(TCP_socket)
    application.start_threading()

    audio_socket = AudioSocketServer(HOST, PORT + 1)

    sys.exit(app.exec())
コード例 #18
0
ファイル: HubConnection.py プロジェクト: goodeveryone/awsl
 def _setState(self, newState, reason=None):
     # print "%s._setState(newState=%s, reason=%s)" % (self, newState, reason)
     TCPConnection._setState(self, newState=newState, reason=reason)
     if self._state == self.Authorizing and not self._didStartAuth:
         self._didStartAuth = True
         self.writeLine("1 auth knockKnock")