Echo server with piping to a file

Echo server with piping to a file

I have a simple echo server and client changed to just send some text to a server. If i use

I have a simple echo server and client changed to just send some text to a server. If i use

./client.o port < file.in

it works and sends file content to a server, but if I try to

./server.o port > file.out

when starting the server, it won't do anything, neither printing into a terminal, nor to a file. I want to be able to write received text to file if it's specified while starting the server process. Here's the receiving loop from the server code:

for(;;) {
        int done, n;
        printf("Waiting for a connection...\n");
        t = sizeof(remote);
        if ((s2 = accept(s, (struct sockaddr *) &remote, (socklen_t *) &t)) == -1) {
            perror("accept");
            exit(1);
        }
        printf("Connected.\n");
        done = 0;
        do {
            n = recv(s2, str, 100, 0);
            if (n <= 0) {
                if (n < 0) perror("recv");
                done = 1;
            }

        if (!done) 
            printf("%s\n", str);
    } while (!done);

What should I do?

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

C/C++ vs. Rust: A developer’s perspective

In this post, you'll see the difference between Rust and C/C++ in a developer’s perspective

Variable Introduction in C#[Bangla]

LIKE | COMMENT | SHARE | SUBSCRIBE A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C# has a speci...