Forum: Ruby How come this doesn't work?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C553cce5633f83100e22f130e10f168d?d=identicon&s=25 Hey You (r3madi)
on 2007-04-11 13:10
require 'socket'
host = 'www.neopets.com'
begin
h = TCPSocket.new(host,80)
rescue
puts "error: #($!)"
else
h.print "POST
/login.phtml?username=r3MaDi&password=mangaka02&destination=/petcentral.phtml
HTTP/1.1\r\nContent-Type: text/html;
charset=UTF-8\r\nHost:"+host+"\r\n\r\n"
h.print "GET /objects.phtml?type=inventory HTTP/1.1\r\n\r\n"
a = h.read
puts a
File.open('Log.txt','w') do |f|
  f.print a
end
end
gets

It just pretty much does the first request which is the post but then
when I tell it to get the other page it doesn't do anything. I made this
code a few seconds ago so I am searching for the answer and I am reading
RFC2616.
7b4707f974af261f71943e1f2046c9ee?d=identicon&s=25 SonOfLilit (Guest)
on 2007-04-11 13:22
(Received via mailing list)
Maybe Connection: Keep-Alive would help? Google it.


Aur Saraf
Ac0085dae0703db56ad7f8cb9e1798ba?d=identicon&s=25 Phillip Gawlowski (Guest)
on 2007-04-11 13:29
(Received via mailing list)
Hey You wrote:

> /login.phtml?username=r3MaDi&password=mangaka02&destination=/petcentral.phtml

If that is a live password, CHANGE IT NOW!


--
Phillip "CynicalRyan" Gawlowski
http://cynicalryan.110mb.com/

Rule of Open-Source Programming #33:

Don't waste time on writing test cases and test scripts - your users are
your best testers.
F0afd024e17c0c4753aa8d618ba9bb0f?d=identicon&s=25 Marcin Raczkowski (Guest)
on 2007-04-11 13:39
(Received via mailing list)
On Wednesday 11 April 2007 11:29, Phillip Gawlowski wrote:
> Hey You wrote:
> > /login.phtml?username=r3MaDi&password=mangaka02&destination=/petcentral.p
> >html
>
> If that is a live password, CHANGE IT NOW!

first of all - ROTFL

second - keep-alive or one connection per request (few web browsers
still do
that - so can you - and you should ensure that you close connection -
passing
a block to #open is prefered way)
C06869c119472a139eb163b72040b0db?d=identicon&s=25 Bertram Scharpf (Guest)
on 2007-04-11 14:00
(Received via mailing list)
Hi,

Am Mittwoch, 11. Apr 2007, 20:10:22 +0900 schrieb Hey You:
> charset=UTF-8\r\nHost:"+host+"\r\n\r\n"
> h.print "GET /objects.phtml?type=inventory HTTP/1.1\r\n\r\n"
> a = h.read
> puts a
> File.open('Log.txt','w') do |f|
>   f.print a
> end
> end
> gets

1. indenting.
2. `else' section is for cleanup. Working code belongs just before
   `rescue'.
3. Don't forget h.close or use h.open
3. Each request needs an own connection. This is NOT a Ruby
   subject.

  require 'socket'
  class String ; def crlf ; gsub "\n", "\r\n" ; end ; end
  begin
    host = 'www.justanotherhttpserver.com'
    puts "-"*32
    [ "POST ...", "GET ..." ].each { |request|
      TCPSocket.open host, 80 do |h|
        h.write request.crlf
        puts h.read
        puts "-"*32
      end
    }
  rescue
    puts "error: #$!"
  end

Bertram
481b8eedcc884289756246e12d1869c1?d=identicon&s=25 Francis Cianfrocca (blackhedd)
on 2007-04-11 14:01
(Received via mailing list)
On 4/11/07, Hey You <r3madi@gmail.com> wrote:
> charset=UTF-8\r\nHost:"+host+"\r\n\r\n"
> when I tell it to get the other page it doesn't do anything. I made this
> code a few seconds ago so I am searching for the answer and I am reading
> RFC2616.
>
> --
> Posted via http://www.ruby-forum.com/.
>
>

Is there some reason why you can't use one of the many different ways
that Ruby provides for accessing web sites?
C553cce5633f83100e22f130e10f168d?d=identicon&s=25 Hey You (r3madi)
on 2007-04-11 23:19
Francis Cianfrocca wrote:
> On 4/11/07, Hey You <r3madi@gmail.com> wrote:
>> charset=UTF-8\r\nHost:"+host+"\r\n\r\n"
>> when I tell it to get the other page it doesn't do anything. I made this
>> code a few seconds ago so I am searching for the answer and I am reading
>> RFC2616.
>>
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>>
>
> Is there some reason why you can't use one of the many different ways
> that Ruby provides for accessing web sites?
But why not use sockets? I just want to learn how to use sockets because
aren't http libraries made up of sockets?
C553cce5633f83100e22f130e10f168d?d=identicon&s=25 Hey You (r3madi)
on 2007-04-11 23:26
Hey You wrote:
> Francis Cianfrocca wrote:
>> On 4/11/07, Hey You <r3madi@gmail.com> wrote:
>>> charset=UTF-8\r\nHost:"+host+"\r\n\r\n"
>>> when I tell it to get the other page it doesn't do anything. I made this
>>> code a few seconds ago so I am searching for the answer and I am reading
>>> RFC2616.
>>>
>>> --
>>> Posted via http://www.ruby-forum.com/.
>>>
>>>
>>
>> Is there some reason why you can't use one of the many different ways
>> that Ruby provides for accessing web sites?
> But why not use sockets? I just want to learn how to use sockets because
> aren't http libraries made up of sockets?
Or what different ways do you guys suggest. I want it to be fast, thats
why I was sticking with "naked" sockets. If you guys can tell me a way
to access web sites as fast as sockets then I will try to learn that
instead.
83ca41657a99b65d99889abe712ba5e2?d=identicon&s=25 Jason Roelofs (Guest)
on 2007-04-11 23:30
(Received via mailing list)
On 4/11/07, Hey You <r3madi@gmail.com> wrote:
> >> --
> Posted via http://www.ruby-forum.com/.
Dealing with the HTTP protocol is not a good way to learn how to use
Sockets. Work with your own little socket server and client if you
really
want to know how to do low-level networking.

And PLEASE go change your password NOW. and don't go posting it again.

Jason
C553cce5633f83100e22f130e10f168d?d=identicon&s=25 Hey You (r3madi)
on 2007-04-11 23:34
Jason Roelofs wrote:
> On 4/11/07, Hey You <r3madi@gmail.com> wrote:
>> >> --
>> Posted via http://www.ruby-forum.com/.
> Dealing with the HTTP protocol is not a good way to learn how to use
> Sockets. Work with your own little socket server and client if you
> really
> want to know how to do low-level networking.
>
> And PLEASE go change your password NOW. and don't go posting it again.
>
> Jason
I will but do you recommend another to access the web that is as fast as
sockets?
Fd22ee3cfc7dac283ce8e451af324f7d?d=identicon&s=25 Chad Perrin (Guest)
on 2007-04-11 23:42
(Received via mailing list)
On Thu, Apr 12, 2007 at 06:34:42AM +0900, Hey You wrote:
> >
> > Jason
> I will but do you recommend another to access the web that is as fast as
> sockets?

I don't know how to put this any more clearly.

I, for one, don't know enough about network programming with Ruby to be
able to answer your question effectively.  That aside, however, a better
version of your previous email would have said this instead:

  I did but do you recommend another to access the web that is as fast
  as sockets?

Once a password is passed into public viewing, your *first priority*
should always be to change it.  It's not something to get around to
later -- it's something to do first.  In fact, if you haven't already
done so by this point, chances are good someone is already making
malicious use of your password (unless you're absurdly lucky).  Jason
wasn't just being mean when he emphasized the importance of changing
your password "NOW".  He's trying to help you avoid the consequences of
a very serious error.
C553cce5633f83100e22f130e10f168d?d=identicon&s=25 Hey You (r3madi)
on 2007-04-11 23:47
Chad Perrin wrote:
> On Thu, Apr 12, 2007 at 06:34:42AM +0900, Hey You wrote:
>> >
>> > Jason
>> I will but do you recommend another to access the web that is as fast as
>> sockets?
>
> I don't know how to put this any more clearly.
>
> I, for one, don't know enough about network programming with Ruby to be
> able to answer your question effectively.  That aside, however, a better
> version of your previous email would have said this instead:
>
>   I did but do you recommend another to access the web that is as fast
>   as sockets?
>
> Once a password is passed into public viewing, your *first priority*
> should always be to change it.  It's not something to get around to
> later -- it's something to do first.  In fact, if you haven't already
> done so by this point, chances are good someone is already making
> malicious use of your password (unless you're absurdly lucky).  Jason
> wasn't just being mean when he emphasized the importance of changing
> your password "NOW".  He's trying to help you avoid the consequences of
> a very serious error.
The thing is I did. I actually didn't notice that I posted my password
but once I saw the post I changed my password. I am sorry if it seemed
like I just ignored his post, I just wanted to know which way you guys
recommend.
4feed660d3728526797edeb4f0467384?d=identicon&s=25 Bill Kelly (Guest)
on 2007-04-12 00:25
(Received via mailing list)
From: "Hey You" <r3madi@gmail.com>
>
> But why not use sockets? I just want to learn how to use sockets because
> aren't http libraries made up of sockets?
>
> Or what different ways do you guys suggest. I want it to be fast, thats
> why I was sticking with "naked" sockets. If you guys can tell me a way
> to access web sites as fast as sockets then I will try to learn that
> instead.

There seem to be several things all mixed together here:

  - You want to learn sockets (good)
  - You are trying to learn sockets and HTTP at the same time
(difficult)
  - You are worried about performance (bad: premature optimization)

If you're interested in learning sockets, that's great.  But to speak
HTTP,
you're going to have to handle the same cases the existing HTTP
libraries
do.  Yes, your code will be using sockets, just like the HTTP libraries
are
using sockets.  Your code will likely exhibit similar performance
characteristics as the HTTP library code, too, provided there's nothing
grossly wrong with either your code or the library code.

Being concerned about how fast your program will be while you're still
in a learning stage is only going to unnecessarily complicate your
decisions.  For more information about this:
http://www.c2.com/cgi/wiki?PrematureOptimization

If your primary interest is learning sockets, you might want to start
with
a simple line-based chat server...  If you really want to learn sockets
and HTTP at the same time, that's your business--just keep in mind that
HTTP will add its own complexity to the problem above and beyond just
learning sockets.


Regards,

Bill
Fa2521c6539342333de9f42502657e5a?d=identicon&s=25 Eleanor McHugh (Guest)
on 2007-04-12 00:37
(Received via mailing list)
On 11 Apr 2007, at 22:34, Hey You wrote:
>> again.
>>
>> Jason
> I will but do you recommend another to access the web that is as
> fast as
> sockets?

I admire your desire to do this stuff at the lowest possible level -
it's a great way to learn. However I take task with your belief that
direct socket programming will be faster than using an HTTP wrapper
library: the round-trip cost of any network communication is orders-
of-magnitude greater than the runtime overhead of using even loosely-
written interpreted code and is the primary limitation on the 'speed'
of your code.


Ellie

Eleanor McHugh
Games With Brains
----
raise ArgumentError unless @reality.responds_to? :reason
This topic is locked and can not be replied to.