C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-20-2005, 03:41 PM   #1
Registered User
 
Join Date: May 2004
Posts: 164
send zip file via socket

Hi,
the platform I am writing the code on is unix based, command line stuff.
I am more accustom to writing in c++ but my current task requires I alter a c program.

I am dropping the data from file to a socket. I read in line by line the entire contents of a file.

Problem is, the send is taking too long, since the file is so large. I need to zip the file and send the contents in a copressed manner. However, I don't know of any means to read from a compressed file, in a line by line manner.

So I decided to just attempt a full file send of the zip file to the destination and then uncompress it. I know how to do a remove file using stdio.h remove() but, I was wondering if there was anyway to send a file in c to a destination address using socke to socket addressing?

In c++ I can send files to different drives but this is unique to me.

I'm sorry I know this is vague, I'm just trying to find a good starting point. Any help would be greatly appreciated.
WaterNut is offline   Reply With Quote
Old 05-20-2005, 08:16 PM   #2
Registered User
 
Join Date: Jan 2005
Posts: 847
A zip file can't realy be read in line by line because it is binary data. It probably contains ocurances of the new line charactor but these are not intended to indicate newlines. You can use the sendfile function.
Quantum1024 is offline   Reply With Quote
Old 05-20-2005, 08:41 PM   #3
#include<xErath.h>
 
xErath's Avatar
 
Join Date: Jun 2004
Posts: 724
do tcp socket work on a text based parsing?? or simply let the programmer decide what's the end or newline or not? i'd bet the second....
xErath is offline   Reply With Quote
Old 05-20-2005, 09:11 PM   #4
Registered User
 
Join Date: Jan 2005
Posts: 847
Quote:
Originally Posted by xErath
do tcp socket work on a text based parsing?? or simply let the programmer decide what's the end or newline or not? i'd bet the second....
tcp sockets are a byte stream, they will send however many bytes you specify without doing any checking of what those bytes are.
Quantum1024 is offline   Reply With Quote
Old 05-24-2005, 09:07 AM   #5
Registered User
 
Join Date: May 2004
Posts: 164
Thanks everyone for your replies and sorry for my late response, I have not been online in a few days. I am researching the sendfile function listed by quantum, the compressed file comment is what I always knew about compressed files, so I did not think that would be possible to read in line by line, thanks for confirming.

Is the sendfile function tcp/ip based? I trying to find the header file where it is defined?
WaterNut is offline   Reply With Quote
Old 05-24-2005, 09:25 AM   #6
+++ OK NO CARRIER
 
quzah's Avatar
 
Join Date: Oct 2001
Posts: 10,260
Is this what you were looking for?

Quzah.
__________________
Hundreds of thousands of dipshits can't be wrong.


Are you up for the suck?
quzah is offline   Reply With Quote
Old 05-24-2005, 09:49 AM   #7
Registered User
 
Join Date: May 2004
Posts: 164
Thanks for the link, I am trying to read it now, I am having issues with my companies web filtering, Too many spyware attacks recently

Is there another way to view this info? Sorry to ask such a question, desprate measures.... not trying to be a pain.
WaterNut is offline   Reply With Quote
Old 05-24-2005, 09:53 AM   #8
Registered User
 
Join Date: Jan 2005
Posts: 847
On a unix based system try:
man sendfile
Quantum1024 is offline   Reply With Quote
Old 05-24-2005, 10:00 AM   #9
Registered User
 
Join Date: May 2004
Posts: 164
awesome, I am reading the man now. Thanks! I hope I will not have to bother anyone else on the matter. Thank you for the pointer.
WaterNut is offline   Reply With Quote
Old 05-24-2005, 11:39 AM   #10
Registered User
 
Join Date: May 2004
Posts: 164
well, I think I am almost there.... I think....

I have to compilation errors based of the structs being created, however, since I using the examples from the senfile man page to base my function off of, I am bit confused as to why the compiler is unhappy.

here is the function:
Code:
int Sndfl ()
{
	 int ffd, tfd;
     off_t off;
     struct sockaddr_in sin;
     in_addr_t  addr;
     int len;
     struct stat stat_buf;

         ffd = open(BARCODE_TABLE, O_RDONLY);
         if (ffd == -1) {
             perror("open");
             exit(1);
         }

         tfd = socket(AF_INET, SOCK_STREAM, 0);
         if (tfd == -1) {
             perror("socket");
             exit(1);
         }

         sin.sin_family = AF_INET;
         sin.sin_addr = INADDR_ANY;    /* Fill in the  appropriate address. */
         sin.sin_port = htons(1130);
         if (connect(tfd, (struct sockaddr *) &sin, sizeof(sin)) <0) {
             perror("connect");
             exit(1);
         }

         if (fstat(ffd, &stat_buf) == -1) {
             perror("fstat");
             exit(1);
         }

         len = sendfile(tfd, ffd, &off, stat_buf.st_size);

         if  (len  ==  -1)  {
             perror("sendfile");
             exit(1);
         }
}
Here are my errors
Code:
utilserv.c: In function `Sndfl':
utilserv.c:115: error: storage size of `stat_buf' isn't known
utilserv.c:130: error: incompatible types in assignment
I am guessing that I have not used this example properly and did not tell the compiler how much buffer space to give stat_buf??

Again, thanks for any help available.
WaterNut is offline   Reply With Quote
Old 05-24-2005, 11:44 AM   #11
Frequently Quite Prolix
 
dwks's Avatar
 
Join Date: Apr 2005
Location: Canada
Posts: 7,629
struct stat doesn't exist according to error #2.

The other error on the line:
Code:
sin.sin_addr = INADDR_ANY
is because INADDR_ANY is not of the same type as sin.sin_addr, I think anyway.

dwk
dwks is offline   Reply With Quote
Old 05-24-2005, 11:49 AM   #12
Registered User
 
Join Date: May 2004
Posts: 164
hmmm... ok, that makes sense

I am used to using such and IP address setup for windows, using winsock, not quite accustom to unix c coding using socket.h,
Thanks for the pointers, I will define my struct and look at using something different for my ip address.
WaterNut is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
File transfer- the file sometimes not full transferred shu_fei86 C# Programming 13 03-13-2009 12:44 PM
Formatting a text file... dagorsul C Programming 12 05-02-2008 03:53 AM
Formatting the contents of a text file dagorsul C++ Programming 2 04-29-2008 12:36 PM
gcc link external library spank C Programming 6 08-08-2007 03:44 PM
System drdroid C++ Programming 3 06-28-2002 10:12 PM


All times are GMT -6. The time now is 01:40 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22