The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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-09-2007 02:49 AM
Reading a file and writing the file name to a param file. thebeginer UNIX for Advanced & Expert Users 1 10-05-2007 04:38 PM
reading/ writing to sockets rein Shell Programming and Scripting 1 09-20-2007 08:57 PM
Reading and Writing Files ? tracydp UNIX for Dummies Questions & Answers 3 08-30-2006 10:24 AM
Reading and writing SCO DAT tapes uing Linux cstovall UNIX for Dummies Questions & Answers 3 04-27-2003 07:59 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-29-2007
lucky001 lucky001 is offline
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 04:48 PM..
  #2 (permalink)  
Old 03-30-2007
Hitori's Avatar
Hitori Hitori is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2006
Posts: 360
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.
  #3 (permalink)  
Old 03-30-2007
lucky001 lucky001 is offline
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.
  #4 (permalink)  
Old 03-30-2007
Hitori's Avatar
Hitori Hitori is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2006
Posts: 360
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:57 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0