Beispiel #1
0
	def accept( self ):
		if self.socket:
			(newSocket, remote) = self.socket.accept()

			connection = TcpConnection( self.transport, self.localAddress, self.localPort, remoteAddress=remote[0], remotePort=remote[1], csocket=newSocket )
			Dispatcher.add( connection, parentObj=self )
			Dispatcher.addListener( connection, self )

			name = Network.getBindingName( connection.transport, connection.remoteAddress, connection.remotePort )
			self.connections[name] = connection

			# Send the TCP connection's connected notification to ourselves.
			# This is a work-around, since we are constructing the connection in the connected state and
			# we do not want to send the event in the TCP connection's constructor.
			newEvent = NetEvent( NetEvent.EVENT_CONNECTED, connection.transport, connection.localAddress, connection.localPort, connection.remoteAddress, connection.remotePort, connection=connection )
			Dispatcher.send( newEvent, srcObj=self, dstObj=self )
Beispiel #2
0
	def inBound_onQueue( self, event ):
		if not event.connection:
			if ( event.localAddress != self.localAddress ) or ( event.localPort != self.localPort ):
				# This is not our binding.
				return

			# Let the network layer choose the local port.
			event.localPort = 0

			# Create a new connection and queue the event in the connection.
			connection = TcpConnection( event.transport, event.localAddress, event.localPort, event.remoteAddress, event.remotePort )
			Dispatcher.add( connection, parentObj=self )
			Dispatcher.addListener( connection, self )

			name = Network.getBindingName( connection.transport, connection.remoteAddress, connection.remotePort )
			self.connections[name] = connection

		Dispatcher.send( event, srcObj=self, dstObj=connection )