LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-22-2008, 08:10 AM   #1
EncrYpted-ErrOr
LQ Newbie
 
Registered: Dec 2007
Posts: 5

Rep: Reputation: 0
Question 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
 
Old 03-22-2008, 09:10 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,260
Blog Entries: 54

Rep: Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841
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.
 
Old 03-22-2008, 10:37 AM   #3
EncrYpted-ErrOr
LQ Newbie
 
Registered: Dec 2007
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by unSpawn View Post
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 View Post
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

Last edited by EncrYpted-ErrOr; 03-22-2008 at 10:46 AM.
 
Old 03-22-2008, 10:50 AM   #4
rubadub
Member
 
Registered: Jun 2004
Posts: 233

Rep: Reputation: 33
Here's a link to a must tutorial on sockets, and here's a little something on the http protocol.
 
Old 03-22-2008, 11:31 AM   #5
LinuxManMikeC
Member
 
Registered: Nov 2007
Location: Provo, Utah
Distribution: Debian and Ubuntu
Posts: 74

Rep: Reputation: 15
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.
 
Old 03-22-2008, 11:46 AM   #6
rubadub
Member
 
Registered: Jun 2004
Posts: 233

Rep: Reputation: 33
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.
 
Old 03-22-2008, 11:57 AM   #7
LinuxManMikeC
Member
 
Registered: Nov 2007
Location: Provo, Utah
Distribution: Debian and Ubuntu
Posts: 74

Rep: Reputation: 15
*SMACKS HEAD*

Yep, missed that, that'll teach me to answer questions when tired. Still quite simple either way.
 
Old 03-22-2008, 12:25 PM   #8
EncrYpted-ErrOr
LQ Newbie
 
Registered: Dec 2007
Posts: 5

Original Poster
Rep: Reputation: 0
thanx for all
but i need any examples or any tutorials to understand Dealing linux sockets with http in c
thanx again
 
Old 03-22-2008, 12:32 PM   #9
rubadub
Member
 
Registered: Jun 2004
Posts: 233

Rep: Reputation: 33
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?
 
Old 03-22-2008, 12:43 PM   #10
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Program to forward tcp sockets to unix domain sockets mikepol Linux - Networking 0 09-27-2007 09:49 AM
Linux Sockets JanusPaul Programming 5 11-14-2004 11:44 AM
Linux sockets linlai Programming 2 07-16-2002 02:51 PM
sockets in linux 2.4.2 kernel arumash Linux - Networking 1 06-29-2002 09:21 PM
Sockets in Linux GhostBoot Linux - Networking 1 05-18-2001 12:36 PM


All times are GMT -5. The time now is 08:41 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration