UNIX Socket FAQ

You are not logged in.

  • Index
  • » Processes
  • » Problem with file transfer thru socket using sub-function method

#1 2005-10-23 07:06 AM

bloodfire
Member
Registered: 2005-10-22
Posts: 8

Re: Problem with file transfer thru socket using sub-function method

Here are the partial of the sub function codes for the sending and receiving file over tcp which is located in the same file:

called from client code using  sendingFile(filename, filebytes)

void sendingFile(char* sendFile, int sendSize) {
.
.
.
							/* open file for reading */
...
							while ((n = read(fdin, data, 100)) > 0){
.
.
.
									if((n2 = write(sockfd, ptr, n)) < 0) {
										perror("Socket writing error");
										exit(1);
									}
.
.
								}
							}
							/* close file */
	return;
}


called from server code using  receivingFile(sockfd, filename, filebytes)

void receivingFile(int getsockfd, char* getFile, int getSize) {
.
.
.


							/* open new file for reading */
					/* compare new file size with reading file size */
						n = read(getsockfd, data, min(100, getSize-curr));
						/* write to file */char *ptr = data;
.
.
.
.
						/* getting new file current write size */
						}
					}
					/* close writing file */
	return;
}

If i put the sendingFile code directly into the client code without using subfunction. It works. But it doesn't work once using it as subfunction.  Am i suppose to return anything from the sendingFile or?

Offline

#2 2005-10-23 05:43 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,736
Website

Re: Problem with file transfer thru socket using sub-function method

Where does "sockfd" come from?  Shouldn't that be passed in as a parameter to
the sendingFile() function??

Offline

#3 2005-10-24 02:34 AM

bloodfire
Member
Registered: 2005-10-22
Posts: 8

Re: Problem with file transfer thru socket using sub-function method

Ok, got it working. Yeah, forgot to pass the actual sockfd parameter. The sockfd was a new 1. Ok cool thanks man.

Offline

  • Index
  • » Processes
  • » Problem with file transfer thru socket using sub-function method

Board footer

Powered by FluxBB