![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| 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 |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
||||
|
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 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. |
|
|||
|
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. |