Sending large file through sockets


 
Thread Tools Search this Thread
Top Forums Programming Sending large file through sockets
# 8  
Old 08-28-2009
Quote:
Originally Posted by botao
here's my two cents: "you just have to do as if in a file copy program" ;

- that's the whole idea behind sockets ... once a connection is established , it's just another good ol' file i/o thing !

- the only detail you should bear in mind is that the default packet size is 1500 bytes, and it's no use reading(receiving) or writing(sending) chunks bigger than this ;

(remember : this is plain bread-and-butter default conditions - for newbies - and anything more complicated than this can be done with proper study)

finally, some sample code (for the client who sends the file):

Code:
int sockfd , count ;
char buf[1500] ;
/* plain connection */
sockfd = socket (AF_INET, ...) ;
connect (sockfd, ...) ;
/* now the good ol' plain file i/o */
while (filesize > 0) {
   count = send (sockfd, buf, 1500, 0) ;
   filesize -= count ;
}

good luck, and success !
alexandre botao
Alexandre V. R. Botao | Unix, C/C++, Shell, LDAP, SSL/TLS, SSH, Perl, Java, Python, Security, ...
Ummm, you left out the part about reading the file into the buffer.

That's why I like sendfile() - it's simpler. It's just open(), fstat() to get the file length, then sendfile().
# 9  
Old 08-31-2009
SYNOPSIS
#include <sys/sendfile.h>

ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count);
DESCRIPTION
Presently (Linux 2.6.9): in_fd, must correspond to a file which supports mmap(2)-like operations (i.e., it cannot be a socket); and out_fd must refer to a socket.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed awk: split a large file to unique file names

Dear Users, Appreciate your help if you could help me with splitting a large file > 1 million lines with sed or awk. below is the text in the file input file.txt scaffold1 928 929 C/T + scaffold1 942 943 G/C + scaffold1 959 960 C/T +... (6 Replies)
Discussion started by: kapr0001
6 Replies

2. Linux

Split a large textfile (one file) into multiple file to base on ^L

Hi, Anyone can help, I have a large textfile (one file), and I need to split into multiple file to break each file into ^L. My textfile ========== abc company abc address abc contact ^L my company my address my contact my skills ^L your company your address ========== (3 Replies)
Discussion started by: fspalero
3 Replies

3. Shell Programming and Scripting

Compare large file and identify difference in separate file

I have a very large system generated file containing around 500K rows size 100MB like following HOME|ALICE STREET|3||NEW LISTING HOME|NEWPORT STREET|1||NEW LISTING HOME|KING STREET|5||NEW LISTING HOME|WINSOME AVENUE|4||MODIFICATION CAR|TOYOTA|4||NEW LISTING CAR|FORD|4||NEW... (9 Replies)
Discussion started by: jubaier
9 Replies

4. Shell Programming and Scripting

Script to search a large file with a list of terms in another file

Hi- I am trying to search a large file with a number of different search terms that are listed one per line in 3 different files. Most importantly I need to be able to do a case insensitive search. I have tried just using egrep -f but it doesn't seam to be able to handle the -i option when... (3 Replies)
Discussion started by: dougzilla
3 Replies

5. Shell Programming and Scripting

Performance issue in UNIX while generating .dat file from large text file

Hello Gurus, We are facing some performance issue in UNIX. If someone had faced such kind of issue in past please provide your suggestions on this . Problem Definition: /Few of load processes of our Finance Application are facing issue in UNIX when they uses a shell script having below... (19 Replies)
Discussion started by: KRAMA
19 Replies

6. Programming

File Transfer over Sockets

Hello there !!!!!!!!! I got some problems trying to transfer a file through sockets. The Server must be in Java and the Client in C++ I came up with this code for the server : BufferedInputStream input; BufferedOutputStream output; public void send_data() throws IOException { ... (7 Replies)
Discussion started by: mcnikolas
7 Replies

7. Programming

Problem in file transfer using sockets

Hai Friends I am writing a c program to transfer files from one system to another using TCP/IP socket programming.. My Recieve Program #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> extern int errno; extern char *sys_erlist; void... (2 Replies)
Discussion started by: collins
2 Replies

8. Shell Programming and Scripting

mailx attachment sending large file

Hi I want to sent attachment file which is 400mb size.(single file, not tar file) is there any way that these kind of large files can be divided into small sizes and sent as attachments thanks with anticipation (3 Replies)
Discussion started by: karthikn7974
3 Replies

9. Programming

Sockets and File descriptors

I am in a Systems programming class this semester, and our current project is to write a program utilizing sockets and fork. For the project, I decided to make my own instant messaging program. I have the code completed, but I have a problem that keeps old clients from communicating with new... (3 Replies)
Discussion started by: gstlouis
3 Replies
Login or Register to Ask a Question