The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Reading and Writing from Excel using Unix scripting AshishK UNIX and Linux Applications 3 11-08-2007 10:49 PM
Reading a file and writing the file name to a param file. thebeginer UNIX for Advanced & Expert Users 1 10-05-2007 01:38 PM
reading/ writing to sockets rein Shell Programming and Scripting 1 09-20-2007 05:57 PM
Reading and Writing Files ? tracydp UNIX for Dummies Questions & Answers 3 08-30-2006 07:24 AM
Reading and writing SCO DAT tapes uing Linux cstovall UNIX for Dummies Questions & Answers 3 04-27-2003 04:59 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-29-2007
Registered User
 

Join Date: Mar 2007
Posts: 2
Reading and Writing file on LAN

Hi gurus

I am not a C programmer but I need to read and write files on a computer on LAN using IP address.

Suppose on a computer that has an IP 192.168.0.2


Any help or code example. I did in JAVA using URL, but do not know how to do in ANSI-C.

In java:
-------
URL url = new URL("http://192.168.0.2/myfile.txt");
......
then reading from this URL file


Any one know the same process in ANSI-C

Regards
Lucky

Last edited by lucky001; 03-29-2007 at 01:48 PM.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-29-2007
Hitori's Avatar
Registered User
 

Join Date: Jun 2006
Posts: 356
When you use URL url = new URL("http://192.168.0.2/myfile.txt"); in Java you actually read the file with the help of HTTP protocol over TCP, to make this in C you need to

1) use sockets (SOCK_STREAM since we are using TCP protocol) to establish connection to the remote server 192.168.0.2 on port 80 (this is default for http protocol)
(see http://beej.us/guide/bgnet/output/htmlsingle/bgnet.html, the great tutorial for sockets programming)
2) you need to send HTTP GET Request to the server over created socket, e.g.
Code:
GET /myfile.txt HTTP/1.0
Host: 192.168.0.2
(see RFC 2616)
3) then you need to parse HTTP Response (if you lucky you just need to remove HTTP header, if not you need to decode base64 encoding, handle HTTP errors etc., all information about what you need to do written in HTTP Response header)
(see RFC 2616)

If you still want to recieve file from remote server in C program try some library for HTTP protocol, you can also use Perl or scp for instance.
Reply With Quote
  #3 (permalink)  
Old 03-30-2007
Registered User
 

Join Date: Mar 2007
Posts: 2
I have gone through the tutorial you mentioned but was scratching my head.

Actually I am fairly new to C and a Java developer, only couple weeks with C. Any code sample example would be great help.

Secondly, I did not find any help once we are connected to socket.
Reply With Quote
  #4 (permalink)  
Old 03-30-2007
Hitori's Avatar
Registered User
 

Join Date: Jun 2006
Posts: 356
Quote:
Originally Posted by lucky001
Secondly, I did not find any help once we are connected to socket.
You need to send HTTP GET Request to the server over created socket. And you recieve the HTTP REsponse through this socket.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:38 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0