示例#1
0
class server(object):
    reg_obj_ip = []

    def __init__(self):
        self.ss = ServerSocket(8888)

    def start(self):
        while True:
            self.s = self.ss.accept()
            self.reg_obj_ip.append(self.s)
示例#2
0
class server(object):
    def __init__(self):
        self.ss = ServerSocket(777)
        self.s = None
        print("accpted", self.s)

    def server_run(self):
        while True:
            self.s = self.ss.accept()
            multi_client(self.s).start()
示例#3
0
class server(Thread):
	def __init__(self,file_name):
		self.list = []
		self.ss = ServerSocket(777)
		f =  open(file_name,"r")
		self.list = f.readlines()

	def run(self):

		while len(self.list):
			s = self.ss.accept()
			server_multi(s,self.list[0]).start()
			self.list.pop(0)
class NetworkListener(Thread):
    """Use a new thread to listen to a network port and place each message
    sent on a new line to the message queue"""
    
    def __init__(self):
        self._serverSocket = ServerSocket(PORT)
        self._isListening = True
        Thread.__init__(self)
        log("Started server on " + str(PORT))
        
    def run(self):
        """Start thread listening to the socket"""
        while(self._isListening):
            self._clientSocket = self._serverSocket.accept()
            self._handleConnection(self._clientSocket)
        
    def _handleConnection(self, socket):
        reader = BufferedReader(InputStreamReader(socket.getInputStream()))

        try:
            line = reader.readLine();
    
            while(line is not None and not self._serverSocket.closed):
                self._handleMessage(line)
                line = reader.readLine();
        except SocketException:
            if self._isListening:
                raise SocketException
            else:
                log("Ignoring socket exception during shutdown")

        socket.close()

    def _handleMessage(self, message):
        """Called for each message received."""
        lock.acquire()
        messageQueue.append(message)
        lock.notifyAll()
        lock.release()

    def stop(self):
        """Stop the server socket and close any open client socket"""
        self._isListening = False

        if(self._serverSocket is not None):
            self._serverSocket.close()

        if(self._clientSocket is not None):
            self._clientSocket.close() 
class Server(object):
    def __init__(self, port):
        self.port = port
        self._listener = ServerSocket(self.port)
        self.speaker = Speaker()
        self.speaker.playAll()
        self.connections = []

    def listen(self):
        while True:
            newConnection = ClientConnection(self,
                                             self._listener.accept(),
                                             self.speaker.newConnection())
            print 'New connection accepted!', newConnection
            self.connections.append(newConnection)
            Thread(target=newConnection.handle).start()

    def deleteConnection(self, connectionTrack):
        self.speaker.deleteConnection(connectionTrack)
示例#6
0
文件: Test_Http.py 项目: hobson/ggpy
 def __init__(self):
     """ generated source for method __init__ """
     #  Create a server socket on the first available port.
     defaultTestingPort = 13174
     ss = None
     while True:
         try:
             ss = ServerSocket(defaultTestingPort)
         except Exception as e:
             ss = None
             defaultTestingPort += 1
         if not ((ss == None)):
             break
     try:
         self.client = Socket("127.0.0.1", defaultTestingPort)
         self.server = ss.accept()
     except Exception as e:
         fail("Could not establish connection: " + e)
         e.printStackTrace()
     assertNotNull(self.client)
     assertNotNull(self.server)
示例#7
0
from java.net import ServerSocket as SS
from java.net import Socket as SO
from java.io import InputStream
from java.io import OutputStream
from java.io import PrintStream as PS
from java.util import Scanner as S

SS_1 = SS(777)
SO_1 = SS_1.accept()
IS_1 = S(SO_1.getInputStream())
OS_1 = PS(SO_1.getOutputStream())
while True:
    if IS_1.hasNext():
        print(IS_1.next())
        print(OS_1.println("received..."))
    else:
        break