Qt tcp/ip server works with telnet, but not python or netcat
Question: I have a Qt tcp/ip server listening on a port. I can talk to it with telnet,
but when I try with netcat the input commands are truncated. When I try to
send it a command through python, it doesn't see anything. Has anyone else run
into an issue like this with a Qt tcp server? Code follows.

Server

    
    
    QTcpServer remoteControlServer;
    
    remoteControlClient = remoteControlServer.nextPendingConnection();
    
    connect(remoteControlClient, SIGNAL(readyRead()), this, SLOT(remoteCommandRead()));
    

The command interpreter -> This is where I suspect the problem is. Is
canReadLine() not doing what I want? I am just sending strings, so the line-
oriented protocol is what I think I should be using.

    
    
     void MainWindow::remoteCommandRead()
     {
        QByteArray lineBuffer; 
        QByteArray consoleString;
        QByteArray command;
        QList<QByteArray> commandList;
    
        while(remoteControlClient->canReadLine())
            {
                lineBuffer = remoteControlClient->readLine();
                lineBuffer.chop(2);
                lineBuffer.simplified();
    
                commandList = lineBuffer.split(' ');
    

The python client

    
    
    import socket
    remote_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server_address = ('address', port)
    remote_sock.connect(server_address)
    remote_sock.sendall('commandString')
    

Many thanks.


Answer: Use

    
    
    trimmedLineBuffer = lineBuffer.trimmed();
    commandList = trimmedLineBuffer.split(' ');
    

instead of

    
    
    lineBuffer.chop(2);
    lineBuffer.simplified();
    

From python append "/r/n" to the end of the string you are sending and
everything will work fine!

