Solved

Socket programming in C

Posted on 2002-07-21
15
644 Views
Last Modified: 2013-12-26

My project is socket programming in c (Filetransfer in c under unix OS). How can I send file from one system to another through C.Please give me  proper guidance
                                               Simi
                                               
                                                   

0
Comment
Question by:simisudevan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +5
15 Comments
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 7169711
This sounds an awful lot like a homework assignment...
0
 
LVL 5

Expert Comment

by:nebeker
ID: 7178262
The server creates a socket and listens for connections.  The client connects to the socket and sends the file...  You'll have to make up your own protocol for how the data is sent, but other than this, it is rather trivial.

What part are you having difficulty with?  What platform are you using?

For your protocol, I would suggest you keep it simple.  For example, your conversation could look something like this:

Server:  listening on socket
Client:  connect to server
Client:  send "filename" (so the server knows how to store the incoming data), and "size" (so the server knows how much to expect)
Server:  ok, send the file
Client:  send "file data"
Server:  send "Received!  Thanks for the file"
0
 

Author Comment

by:simisudevan
ID: 7179108
Hai nebeker
                Thanks for your valuable suggestion. But how we can implement it in C.
 I am totally new to this topic. I need proper guidance in socket programming.I just know how to send messages  from one computer to another. But I have no idea about filetransfer.

Thankyou  once again
                                Simi
           
             

     
0
 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

 
LVL 5

Expert Comment

by:nebeker
ID: 7179228
There's not much difference between sending messages (which you already know how to do) and sending a file.  The main one is that your messages are probably fixed-length, or are strings terminated by nulls..   When sending a file, you use the same process, except that you need to send the filesize across first, then you just shove all of the file data into the socket :)

So, your client would do this:

open socket
send "File=filename.ext; size=10000"
read in the 10000 byes of the file
send <raw file data>
close socket

your server would have to parse the first message, and then wait for the next 10,000 bytes to come along...

It's pretty simple.  How much do you have working already?  If you post that, I can show you what you need to add...
0
 
LVL 5

Expert Comment

by:nebeker
ID: 7202021
Have you made any progress on this?  Do you need help with anything specific?
0
 

Author Comment

by:simisudevan
ID: 7204867

Hai nebeker
           Can I make this small project userfriendly ie
Can I include graphich functions in this project. I got a new topic SVGAlib. But I did't know about this.
                                               Simi    
0
 
LVL 5

Expert Comment

by:nebeker
ID: 7204920
I would suggest you get the file transfer stuff working first as a command-line version, before you start thinking about making a nice GUI for it...
0
 
LVL 1

Accepted Solution

by:
cyberpassion earned 50 total points
ID: 7211049
Hello Simi,

I have the perfect answer for you, go to

http://www.ecst.csuchico.edu/~beej/guide/net/

It will explain all about socket programming in a language anybody can understand (even me !)...

It helped me a *lot* and I now know how to program sockets to send data from one machine to another ! Am I currently using this (and modifying the whole concept) a lot for a project I am working on using OSE delta... for carrier-class wireless transmissions. Also check Richard Stevens guide to Unix network programming.

Hope this helps !
Martin


0
 

Expert Comment

by:SHENNI
ID: 7355650
how about using sendfile() function.
0
 

Expert Comment

by:pari205
ID: 7667379
hai
   visit:
             http://www.linuxgazette.com/issue74/tougher.html
0
 
LVL 21

Expert Comment

by:tfewster
ID: 8074605
This question has been abandoned. I will make a recommendation to the moderators on its resolution in a week or two. I don't have the time/knowledge/resources to test this, so I would appreciate any comments that would help me to make a recommendation.

If you are recommending your own comment as an answer, please review it to ensure it is 100% correct, is the only solution and does not duplicate another Experts comments. Otherwise the recommendation should be to save as a PAQ (or delete)
 
In the absence of responses, I may recommend DELETE unless it is clear to me that it has value as a PAQ. Silence = you don't care
 
tfewster
Cleanup Volunteer
0
 
LVL 5

Expert Comment

by:nebeker
ID: 8075219
I would recommend you PAQ this question & award points to cyberpassion.  The link to "Beej's Guide to Network Programming" is very handy...
0
 
LVL 21

Expert Comment

by:tfewster
ID: 8189669
nebeker, thanks for reviewing this question.

I will leave a recommendation for this question in the Cleanup topic area as follows:

- Answered by cyberpassion

Please leave any comments here within the next 7 days

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

tfewster
Cleanup Volunteer
0
 

Expert Comment

by:SpideyMod
ID: 8234492
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0
 

Expert Comment

by:pari205
ID: 8237633
Refer "UNIX NETWORK PROGRAMMING" BY RICHARD STEPHENS
there is day time server and daytime client
modify it as like ur wish

if u need code exactly reply
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question