Пример #1
0
def run_client(host, port):
    selfClient = Client(host, int(port))
    selfClient._connect()
    input.append(selfClient.clientSocket)
    input.append(sys.stdin)
    running = True
    print "Connection established. Please set your name with /name to start chatting."

    while running is True:
        inready, outready, exready = select.select(input, [], [])

        for s in inready:
            # Receiving information from the other user (the server).
            if s == selfClient.clientSocket:
                data = s.recv(SIZE)
                if data:
                    print data
                else:
                    s.close()
                    print ERROR_MSG['conClosed']
                    running = False
                    break
            # Sending information to the other users via the server.
            if s == sys.stdin:
                userText = sys.stdin.readline()
                line = userText.rstrip("\r\n")
                selfClient.clientSocket.send(line)

    selfClient._close()
Пример #2
0
def run_client(host, port):
    selfClient = Client(host, int(port))
    selfClient._connect()
    input.append(selfClient.clientSocket)
    input.append(sys.stdin)
    running = True
    print "Connection established. Please set your name with /name to start chatting."   

 
    while running is True: 
        inready,outready,exready = select.select(input,[],[]) 

        for s in inready:
            # Receiving information from the other user (the server).
            if s == selfClient.clientSocket:
                data = s.recv(SIZE)
                if data:
                    print data
                else:
                    s.close()
                    print ERROR_MSG['conClosed']
                    running = False
                    break
            # Sending information to the other users via the server.
            if s == sys.stdin: 
                userText = sys.stdin.readline() 
                line = userText.rstrip("\r\n")
                selfClient.clientSocket.send(line)

    selfClient._close()
Пример #3
0
def main():
    host = raw_input("Provide an IP address for the bot: ")
    port = raw_input("Provide a port for the bot: ")
    botSocket = Client(host, int(port))
    botSocket._connect()
    botSocket.clientSocket.send("/name Lizbot\n")
    running = True
    input = [botSocket.clientSocket, sys.stdin]

    while running is True:
        inready, outready, exready = select.select(input, [], [])
        for s in inready:
            if s == botSocket.clientSocket:
                data = s.recv(SIZE)
                if data:
                    tempData = data.rstrip("\r\n")
                    splitData = tempData.split(" ", 4)
                    splitData.append(
                        "\n")  # Placeholder to fix argument issues...
                    if splitData[1] == "Lizbot":
                        if commandDict.has_key(splitData[2]):
                            commandDict[splitData[2]](botSocket.clientSocket)
                        else:
                            pass
                else:
                    running = False
                    break
            if s == sys.stdin:
                pass