I want to be able to save files on a server made in c

0

The truth is that I have just started with the issue of socket in cy and I already programmed the client and the server with the tcp protocol, but I wanted to be able to save files in the server in order to download it from the client in another pc or download them from the telnet terminal command of linux, if someone could guide me on the subject I would be very grateful, I'll leave the server code. Thanks in advance.

enter the code here

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netdb.h>

#define PUERTO     2000

int main(){

socklen_t longc;
int socket_host;
int socket_cliente;

char buffer[BUFFERSIZE];

socket_host = socket(AF_INET, SOCK_STREAM,0);

struct sockaddr_in servidor, cliente;
bzero((char * )&servidor, sizeof(servidor));

servidor.sin_family = AF_INET;
servidor.sin_port   = htons(PUERTO);
servidor.sin_addr.s_addr = INADDR_ANY;  

if(bind(socket_host,(struct sockaddr *)&servidor, sizeof(servidor)) == -1){
    printf("Error en el bind\n");
    return 1;
}
printf("Direccion %s:%d\n", inet_ntoa(servidor.sin_addr), htons(PUERTO));
listen(socket_host, 2);

while(free){
    longc = sizeof(cliente); // TAMANO DE LA ESTRUCTURA CLIENTE
    socket_cliente = accept(socket_host,(struct sockaddr *)&cliente, &longc);
    printf("Escuchando en el puerto %d\n", ntohs(cliente.sin_port));

    recv(socket_cliente,buffer,512,0);
    printf("%s",buffer);
    send(socket_cliente,"listo\n",7,0);
    }
return 0;
}
    
asked by Frijolito 20.10.2018 в 18:56
source

0 answers