File transfer using socket


 
Thread Tools Search this Thread
Top Forums Programming File transfer using socket
# 1  
Old 03-22-2005
File transfer using socket

Hi I need to transfer a whole file between a client ad a server. How can I do that?
Using read and write whit sockets I have problem with buffer size of both client and server. I tried to send the number of blocks(Filesize / Buffersize) and start transfer sending block by block, but what if I don't know the receiving buffer size? Is there a more "elgant" way to do this?
Thanx in advance!
# 2  
Old 03-25-2005
You are writing your own transfer client/server, so you have to set up some sort of protocol for transferring data.

You could do this as per your preferences; I suggest the following:

when client connects, send recv. block size to server; then server will read a max of those many bytes when reading a file. When server starts sending data, the first x bytes (x can be chosen by you) will be the number of bytes that are gonna be sent by the server to the client, so that the client knows how many bytes to expect and can throw an error if less than that is received. And have the client send an ACK byte or and ACK message to the server upon successful transfer and a NACK byte or message if there is an error during transfer.

Hope this helps!

Cheers!
# 3  
Old 04-01-2005
Thanx

Ok, actually I did some error but now it works.
Thanks!!!
# 4  
Old 02-02-2009
transfer size ?

hi
i wrote client server programs for file transfer.
it copies the sent file content on a file ,created on client side.
but additionaly it stored some garbage text at the end...which also increased the size of the file.
how can i get actual file content?
# 5  
Old 02-26-2009
thanksSmilie
# 6  
Old 02-26-2009
For new questions it is best to make new threads, instead of bumping unrelated 4-year-old threads whose posters may be long gone.

If extra data is being written, you need to be more careful to write only the same number of bytes that you read from the socket. If you could post source code, we might be able to show you where this mistake is happening.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Download file with socket syscall

Hello to all I want download a file in osx intel 64 with NASM , I want to use socket syscall This is part of my code section .data command db "GET /test/2.gif HTTP/1.1\r\nHost: 10.1.1.187\r\n\r\n", 0 ; url db "http://172.16.207.153/test/2.gif", 0 global main... (1 Reply)
Discussion started by: recher.jack
1 Replies

2. UNIX for Advanced & Expert Users

UDP Socket File Sharing

Hai, I am having one server/client both running in different host in UDP. How can i assure whether the data is recieved properly in client side. I am writing 250 KB in Server and client reading only 150 KB data. I am using select write in server and select read in client also.If i am putting one... (1 Reply)
Discussion started by: andrew.paul
1 Replies

3. IP Networking

Clarification - Setting socket options at the same time when socket is listening

I need clarification on whether it is okay to set socket options on a listening socket simultaneously when it is being used in an accept() call? Following is the scenario:- -- Task 1 - is executing in a loop - polling a listen socket, lets call it 'fd', (whose file descriptor is global)... (2 Replies)
Discussion started by: jake24
2 Replies

4. Programming

Socket Programming file sending

Hello everyone,, I am doing one socket programming.Is it possible to send one file from client to server without using buffer??.I am sending tar files. Thanks in Advance (9 Replies)
Discussion started by: andrew.paul
9 Replies

5. Programming

Error with socket operation on non-socket

Dear Experts, i am compiling my code in suse 4.1 which is compiling fine, but at runtime it is showing me for socket programming error no 88 as i searched in errno.h it is telling me socket operation on non socket, what is the meaning of this , how to deal with this error , please... (1 Reply)
Discussion started by: vin_pll
1 Replies

6. Programming

socket function to read a webpage (socket.h)

Why does this socket function only read the first 1440 chars of the stream. Why not the whole stream ? I checked it with gdm and valgrind and everything seems correct... #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <string.h> #include... (3 Replies)
Discussion started by: cyler
3 Replies

7. Programming

Socket Programming Send File

Hello my friends; Look at this 2 program: Client: #include <stdlib.h> #include <stdio.h> #include <string.h> #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <arpa/inet.h> int main ( int agrc, char *argv ) { int Socket; struct sockaddr_in... (5 Replies)
Discussion started by: htabesh
5 Replies

8. Programming

which socket should socket option on be set

Hi all, On the server side, one socket is used for listening, the others are used for communicating with the client. My question is: if i want to set option for socket, which socket should be set on? If either can be set, what's the different? Again, what's the different if set option... (1 Reply)
Discussion started by: blademan100
1 Replies

9. UNIX for Advanced & Expert Users

connect problem for sctp socket (ipv6 socket) - Runtime fail Invalid Arguments

Hi, I was porting ipv4 application to ipv6; i was done with TCP transports. Now i am facing problem with SCTp transport at runtime. To test SCTP transport I am using following server and client socket programs. Server program runs fine, but client program fails giving Invalid Arguments for... (0 Replies)
Discussion started by: chandrutiptur
0 Replies

10. Programming

Get the file descriptor of a socket file. C vs Python.

Hi, I want to validate that a file is a socket file on Linux. I know I can do this using the S_ISSOCK macro, but I am not sure how to get the file descriptor for the socket file. For example, I know that /tmp/mapping-foo is a socket file. In Python I can do something like this: >>> import... (2 Replies)
Discussion started by: goon12
2 Replies
Login or Register to Ask a Question