![]() |
| | #1 |
| Registered User Join Date: May 2004
Posts: 164
| send zip file via socket 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 | |
| | #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 | |
| | #3 |
| #include<xErath.h> 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 | |
| | #4 | |
| Registered User Join Date: Jan 2005
Posts: 847
| Quote:
| |
| Quantum1024 is offline | |
| | #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 | |
| | #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 | |
| | #8 |
| Registered User Join Date: Jan 2005
Posts: 847
| On a unix based system try: man sendfile |
| Quantum1024 is offline | |
| | #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 | |
| | #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);
}
}
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 Again, thanks for any help available. |
| WaterNut is offline | |
| | #11 |
| Frequently Quite Prolix 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 ![]() dwk |
| dwks is offline | |
| | #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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |