Я пытаюсь создать программу на tcp / server и tcp / client очень низкоуровневого соединения, но я получаю ошибки при подключении ... так что я могу сделать, чтобы сделать этот исполняемый файл.
TCP-СЕРВЕР
int main(){
char server_msg[256]="You Successfully connected to server";
int network_socket;
network_socket=socket(AF_INET,SOCK_STREAM,0);
struct sockaddr_in server_address;
server_address.sin_family = AF_INET;
server_address.sin_port = htons(9000);
server_address.sin_addr.s_addr = INADDR_ANY ;
bind(network_socket, (struct sockaddr *) &server_address,sizeof(server_address));
listen(network_socket,5);
int client_socket;
client_socket = accept(network_socket,NULL,NULL);
send(client_socket,server_msg,sizeof(server_msg),0);
close(network_socket);
return 0;
}
TCP-КЛИЕНТ
int main(){
int network_socket;
network_socket=socket(AF_INET,SOCK_STREAM,0);
struct sockaddr_in server_address;
server_address.sin_family = AF_INET;
server_address.sin_port = htons(9000);
server_address.sin_addr.s_addr = INADDR_ANY ;
int connection_status;
connection_status= connect(network_socket, (struct sockaddr *) &server_address,sizeof(server_address));
if(connection_status == -1 ){
printf("\nWe have got an error while connecting to server!! \n\n");
}
char recieve_message[256];
recv(network_socket, recieve_message,sizeof(recieve_message),0);
printf("The Data we Recieved : ",recieve_message);
close(network_socket);
return 0;
}
ошибок
cc5vccvW.o server-tcp.c:(.text+0x7d): undefined reference to `__imp_socket'
cc5vccvW.o server-tcp.c:(.text+0x97): undefined reference to `__imp_htons'
cc5vccvW.o server-tcp.c:(.text+0xc0): undefined reference to `__imp_bind'
cc5vccvW.o server-tcp.c:(.text+0xd9): undefined reference to `__imp_listen'
cc5vccvW.o server-tcp.c:(.text+0xf8): undefined reference to `__imp_accept'
cc5vccvW.o server-tcp.c:(.text+0x122): undefined reference to `__imp_send'
[Error] ld returned 1 exit status