0

I am making a program to show the Linux(Ubuntu) PTY bash output data on the windows console. But, It doesn't look friendly to show some bytes such as color bytes. Have a protocol document to indicate how to parse it? Thanks.

2020-10-03: I made two programs that a pty server in Linux and a pty client in windows, They are communicating over TCP/IP. The server program's code like below:

server->onBufferReceived = [&mpty](EasyTCP::IConnection* c, EasyTCP::AutoBuffer data)
{
    int ret = write(mpty, data.data(), data.size());
    ...
};

ret = openpty(&mpty, &spty, NULL, NULL, NULL);
if (ret == -1)
{
    fprintf(stderr, "openpty failed, err[%d]: %s", ret, strerror(errno));
    return 1;
}

printf("%s\n", ttyname(spty));

pid_t child = fork();
if (child == -1)
{
    fprintf(stderr, "fork failed, err[%d]: %s", ret, strerror(errno));
    return 1;
}

if (child == 0)
{
    login_tty(spty);
    execl("/bin/bash", "");
    return 0;
}
assert(server->open(7777));
...

if (FD_ISSET(mpty, &rset))
{
    int n = read(mpty, buf, sizeof(buf) - 1);
    ...

    buf[n] = 0;
    ...
    assert(connection->send(sendBuf));
}

The client program's code like below:

client->onBufferReceived = [](EasyTCP::IConnection* c, EasyTCP::AutoBuffer data)
{
    printf(data.data());
    fflush(stdout);

    data.resize(0);
    assert (c->recv(data, false));
};
...

client->connect("xxxxxx", xxxx);
....
int k = getchar();
if (k < 0 || k > 255)
{
    fprintf(stderr, "getchar k = %d", k);
    continue;
}
char c = (char)k;

EasyTCP::AutoBuffer sendBuf(&c, 1);
sendBuf.resize();
assert (client->send(sendBuf));

But the client program shows some bytes not friendly.

0

1 Answer 1

0

I found a document about the protocol. See https://en.wikipedia.org/wiki/ANSI_escape_code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .