Active7 years, 3 months ago
- Hi, I made a Windows Communication Foundation Application that sends files via TCP from a client to a Service host. These files are converted in an Array of bytes (byte[] file.
- I need to create a program that has both a server and a client and can transmit PDF and text files between the two using UDP as the underlying carrier.
- Serialize Object Over TCP; File Transfer Resume In C#; Sending File Over TCP; How Do I Send Multiple Files Over Tcp At The Same Time In C Sharp? General Discussion.
Hy all today i will show you how to make a basic File Transfer console app. This is just to show you how easy it is to receive and send files in c#.net.
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:
Server terminal:
Client terminal:
• You don’t have money on Steam account?You don’t really want to pay for a Steam game?You searched for a Steam Key Genera. Free download flatout 2 full version. • Far Cry Primal is available on PlayStation 4, XBOX One, and PC. • We present to you the new and updated Garmin GPS Unlock Key Code Generator – Keygen 2015We decide to create this Garmin. • Download latest Godus Wars cd key generator and generate your own free activation cd key.
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
Tcp File Transfer Program In C
Thank you very much!
Dunes26.5k77 gold badges5050 silver badges7171 bronze badges
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:Tcp File Transfer Program In C
<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.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.
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.
File Transfer Android
DunesDunes
26.5k77 gold badges5050 silver badges7171 bronze badges