ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.
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.