Active7 years, 3 months ago
I'm trying TCP file transfer on Linux. After establishing the connection, the server should send 'send.txt' to the client, and the client receives the file and saves it as 'receive.txt'. Then the connection breaks.
The correct input and output should be:
I want to write a server side application which allows several users to exchange files (not above 3MB) in the following way: user A connects to (server) S. User B connects to S. User C connects S. I am trying to send an image file from a server to a client both which have been made manually in C. The length of the file to be sent by the server is only known to the server when it's sending the file so the buffer is dynamically generated in the server, something like this.
Server terminal:
Client terminal:
And both the server and client should exit after the process.
But what I've got now gives
Also, an EMPTY 'receive.txt' is generated.
My code was first written for transferring simple strings, and it worked correctly. So I guess the problem lies in the file transferring part.
My code is as follows:
server.c
client.c
Thank you very much!
Dunes26.5k77 gold badges5050 silver badges7171 bronze badges
We Transfer Files
goldfrapp04goldfrapp0492944 gold badges2222 silver badges4040 bronze badges
2 Answers
You need to add code to the
f_block_sz
code. recv()
has a few posible return values:<0
-- Error, error number inerrno
(errno.h
)0
-- Connection closed>0
-- Data read, number of bytes
You need to handle the second case. Add this
else
case:So that the loop will be broken when the server closes the connection, and your code will print you
LinuxiosLinuxios[client] connection lost
and exit.![Transfer Transfer](https://www.downloadthat.com/images/screen/Client_Server_Comm_Lib_for_Visual_Basic-258193.gif)
28.2k1010 gold badges7474 silver badges104104 bronze badges
You have another problem in that your server program is multiprocess and forks every time it gets an incoming connection. The parent stays alive to accept new connections and the child processes the connection. The exit from the child process is not enough to cause the parent to exit as well.
If you only want to process one connection then don't use fork.
Philip Sparke, 'Dance Movements' Adam Gorb, 'Away Day. A handout or electronic file of the major points of the presentation may be prepared. Philip Sparke: Dance Movements: Philip Sparke: Ritmo Jondo: Carlos Surinach: Paeans and Dances of Heathen Iberia. Flowerdale (Solo Piccolo Trumpet With Piano). Piccolo Trumpet sheet music by Philip Sparke. Each of the four movements is based on well. Philip Sparke is a composer best known for his. Some parts of the curriculum lent themselves very well to dance movements such as exploring symmetry. Spring Concert “Songs and Dances. Dance Movements.Philip Sparke I. Masterwork, Dance Movements. Dance Movements Sparke Pdf Free Welcome to the Website of Sir Peter Scott EX-Vice-Chancellor of Kingston University (Now Part-time Professor at Institute of Education, University of London). You can buy my music here, and in many cases preview the score and hear a snippet of the piece. Dance Movements Philip Sparke Ritmico (b. 1951) Molto Vivo (for the woodwinds) Lento (for the brass) Molto Ritmico Radiant Joy Steven Bryant. Dance movements sparke pdf free.
If you wish to continue your current setup then you will need to change the child process to use
_exit
instead of exit
and get the parent process to handle the SIGCHLD
signal (received when a child process exits).ie.
DunesDunesUsb C File Transfer
26.5k77 gold badges5050 silver badges7171 bronze badges