LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   help in Linux Sockets (https://www.linuxquestions.org/questions/programming-9/help-in-linux-sockets-629842/)

EncrYpted-ErrOr 03-22-2008 08:10 AM

help in Linux Sockets
 
hello every body :)

i need some help in linux sockets

how i can read text files remotely

like this

Code:

http://www.linuxquestions.org/textfile.txt
i Need simple code is doing this process

thnx 4 all

unSpawn 03-22-2008 09:10 AM

Code:

exec 3<>/dev/tcp/www.linuxquestions.org/80
echo -e "GET /textfile.txt HTTP/1.0\n\n" >&3
cat <&3

Next time please post the code you've got or at least what you've researched or tried. Else it would be easy to accuse you of having us do your homework for you and that's against the LQ Rules.

EncrYpted-ErrOr 03-22-2008 10:37 AM

Quote:

Originally Posted by unSpawn (Post 3096882)
Code:

exec 3<>/dev/tcp/www.linuxquestions.org/80
echo -e "GET /textfile.txt HTTP/1.0\n\n" >&3
cat <&3


ohh sorry i Forget tell you the language

i need the answer in c language


Quote:

Originally Posted by unSpawn (Post 3096882)
Next time please post the code you've got or at least what you've researched or tried. Else it would be easy to accuse you of having us do your homework for you and that's against the LQ Rules.

ok , i will post my tried , this is not my homework But I learn sockets myself this period

thanks for replay

rubadub 03-22-2008 10:50 AM

Here's a link to a must tutorial on sockets, and here's a little something on the http protocol.

LinuxManMikeC 03-22-2008 11:31 AM

Actually, for just sending text to a web browser, you don't even need to touch the HTTP protocol. Just dump a pre-determined text file back to the client upon connection. But it won't hurt to study other higher level protocols after you get the hang of sockets.

rubadub 03-22-2008 11:46 AM

But he(?) whishes to request a file from a http server, therefore the request would look something like this:
Quote:

GET /textfile.txt HTTP/1.1
for instance if you were using telnet, your session might go a bit like:
Code:

$ telnet www.google.co.uk 80
Trying 64.233.183.147...
Connected to www.google.co.uk.
Escape character is '^]'.
GET /index.html HTTP/1.0

HTTP/1.0 302 Found
Location: http://www.google.co.uk/index.html
Cache-Control: private
Set-Cookie: PREF=ID=62e869dae5fff652:TM=1196907817:LM=1196907817:S=-l9_a5lDWAo0BuPS;
                        expires=Sat, 05-Dec-2009 02:06:57 GMT; path=/; domain=.google.com
Content-Type: text/html
Server: gws
Content-Length: 231
Date: Thu, 06 Dec 2007 02:06:57 GMT
Connection: Close

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.co.uk/index.html">here</A>.
</BODY></HTML>
Connection closed by foreign host.


LinuxManMikeC 03-22-2008 11:57 AM

*SMACKS HEAD*

Yep, missed that, that'll teach me to answer questions when tired. Still quite simple either way.

EncrYpted-ErrOr 03-22-2008 12:25 PM

thanx for all
but i need any examples or any tutorials to understand Dealing linux sockets with http in c
thanx again

rubadub 03-22-2008 12:32 PM

That first example I gave you shows examples of tcp/ip connections, the second (+ other posts) show examples of the http protocol. Basically after connecting to the server, the only difference is the commands sent, i.e. send a 'GET' command and it shall be served... It's easier than you think... The telnet example can be used as a client for virtually any protocol, so you might like to start with that?

theNbomr 03-22-2008 12:43 PM

I strongly recommend Beej's Guide, as pointed out by a previous poster, for a bunch of very good examples and good tutorial text.
--- rod.


All times are GMT -5. The time now is 01:24 PM.