ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need some help with the following C program that runs on Linux:
1) The server part:
The program is invoked via console where parameters are passed to it. The parameters will include a path to a file (of type .sh) and the ip addresses to which to send that file. The program has to wait for acknowledment from the destination host that the latter has received it, and then terminate.
2) The client part
The program runs in the background as a daemon and waits for any new packets destined for it. When it receives the file, it executes it. It also has to send an acknowledment of receipt to sender host.
No it's my own work..I wanted s.o to guide me to some program source code that ressembles this program..I'm not asking s.o to do it for me..just a starting point on which I can build, that's all.
I did loads of searches for simple file transfer programs but no success, esp when it comes to the file transfer and daemon part..
So If s.o knows of some program that ressembles this, pls give me the link. any tips with regard to the writing of this program are also very much welcomed.
Well in that case, you could take a look at scp seriously. It implements a lot of encryption that you wouldn't need but basically it's a client program that communicated with sshd to transfer files
MAny thx for the replies and very useful links..as far I have read and searched, I've never come across program that do file transfer, say, a .txt file, via sockets. I've only seen strings being sent. How do I "convert" that .txt file into packets?
I've never come across program that do file transfer, say, a .txt file, via sockets. I've only seen strings being sent. How do I "convert" that .txt file into packets?
The networking subsystem in the OS kernel (in this case, the TCP/IP stack) does that for you. You just read() the bytes you want to send(), literally. Play with it. I remember reading Beej's guide some years ago. It's enough to get you going. Read the FAQ's too: Sockets, TCP/IP, Raw sockets.
PS: Note that with UDP, each sendto() maps to one IP packet, possibly fragmented using IP fragmentation (which is different from fragmenting data into various IP packets)
I've only seen strings being sent. How do I "convert" that .txt file into packets?
Data is data, it does not matter if it's a text file or user input or ...
If it's a textfile, you can read a file with e.g. fgets (reads a line at a time). Next send it over the socket; the number of bytes is the length of the string.
Oh ja, be aware of the string terminator. Either you send it (the length will be one byte more, or you handle it at the receiving end).
Last edited by Wim Sturkenboom; 04-25-2006 at 11:58 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.