Client sends file name first, and the server makes a file with that name to write data into it.
The file name is cast from command argument, which is in form like 'file.txt'. The problem is that an error occurs every time I cast a file name other than '.txt'.
I'm testing the codes under circumstance with packet loss, with 15% probability. If a loss occurs the whole packet will go away, not leaving any part of it. That's why I thought the file name is lost every time. If the file name packet is not lost, the file would open with a proper name. So I thought it would receive a proper one at least one every 10 times, but it hasn't ever.
//send the file name to the server
byteSent = sendto(sockfd, argv[3], sizeof(argv[3]), 0,
(struct sockaddr*)&addr, addr_size);
There isn't any other problem with those variables, I guess. It worked as I expected when packet loss not assumed. I changed the 3rd argument from strlen(argv[3]) + 1, but nothing had changed from it.
if((byteRcvd = recvfrom(sockfd, buf, sizeof(buf), 0,
(struct sockaddr*)&addr, &addr_size)) < 0)
exit(1);
byteRcvd = BUFFER_SIZE;
fp = open(buf, O_RDWR | O_CREAT, 0644);
//printf("file \"%s\" is opened\n", buf);
Can I solve this problem by modifying the codes?