Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt tcp/ip server (sort of) works with raw telnet, but not python, netcat or PuTTy w/telnet



  • 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. The strangest behaviour is with PuTTY (see below). 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 -> If it's not the setup or configuration of the server, 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. I do not undersand why, but if I chop two bytes off of the string, telnet works. The last two bytes are \r\n. Shouldn't simplified() remove those? If simplified doesn't work on a QByteArray why does this compile without errors in Qt Creator?

    @ 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')@

    Using telnet trhough PuTTy I discovered that there is some junk hanging around somewhere which I need to flush, but I don't know how much there is, where it is coming from or how to filter it out. When I enter a command using PuTTy the first time, the Qtserver side replies
    Unknown: ���� ����'������connect.
    The next time it gets Unknown: ���� ����'��'connect'
    Then Unknown: ��$connect
    And eventually it works and accepts the command Command: connect

    Any ideas about what is going on here?

    Many Thanks.


Log in to reply