I am trying to think about how to transfer a video file over a TCP socket. I made a standard socket program, but after the command readI’m not sure how I can save it.
Code example
//bind server socketfd
if (bind(sfdServer, (struct sockaddr*)&adrServer, ServerAddrLen) < 0)
error("ERROR binding");
listen(sfdServer, 5);
while(1){
printf("Waiting for connections...\n");
sfdClient = accept(sfdServer, (struct sockaddr*)&adrClient, &ClientAddrLen);
if(sfdClient < 0)
error("ERROR accepting");
printf("Connection Established.\n");
//set buffer to zero
bzero(buff, 2048);
printf("Reading from client.\n");
numChar = read(sfdClient, buff, 2048);
//What should go here?
close(sfdClient);
close(sfdServer);
}
Would I just save the buffer as a movie.mp4 file or something like that? I understand that I may need to resize my buffer or perhaps send it to pieces. But I can not find good information on how to do this. Any help or point in the right direction would be appreciated!
source
share