[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Establishing new TCP Socket connection

Joe Van Dyk

7/5/2005 9:03:00 PM

Hi,

If I want to establish a new TCP connection every time I need to
access data (the server doesn't want to keep old connetions around),
is there any reason why I can't do something like:

def send_message_and_recv_response
server = TCPSocket.new @server_ip, @server_port
server.puts "the message"
result = server.recv
end


5 Answers

Joe Van Dyk

7/5/2005 11:40:00 PM

0

No response needed on this... it all seems to work ok.

On 7/5/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> Hi,
>
> If I want to establish a new TCP connection every time I need to
> access data (the server doesn't want to keep old connetions around),
> is there any reason why I can't do something like:
>
> def send_message_and_recv_response
> server = TCPSocket.new @server_ip, @server_port
> server.puts "the message"
> result = server.recv
> end
>


Eric Hodel

7/5/2005 11:49:00 PM

0

On 05 Jul 2005, at 14:03, Joe Van Dyk wrote:

> If I want to establish a new TCP connection every time I need to
> access data (the server doesn't want to keep old connetions around),
> is there any reason why I can't do something like:
>
> def send_message_and_recv_response
> server = TCPSocket.new @server_ip, @server_port
> server.puts "the message"
> result = server.recv
> end

You could be more friendly to the other end by adding an explicit close:

def do_the_stuff
sock = TCPSocket.new @ip, @port
sock.puts "message"
return sock.recv
ensure
sock.close unless sock.nil?
end

--
Eric Hodel - drbrain@segment7.net - http://se...
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04



Adam P. Jenkins

7/6/2005 12:06:00 AM

0

Joe Van Dyk wrote:
> Hi,
>
> If I want to establish a new TCP connection every time I need to
> access data (the server doesn't want to keep old connetions around),
> is there any reason why I can't do something like:
>
> def send_message_and_recv_response
> server = TCPSocket.new @server_ip, @server_port
> server.puts "the message"
> result = server.recv
> end

Sure, except you should explicitly close the connection as well at the
end of your block rather than letting the socket object's finalizer do
it whenever the GC gets around to calling it. So, something like:

def send_message_and_recv_response
server = nil
server = TCPSocket.new @server_ip, @server_port
server.puts "the message"
result = server.recv
ensure
server.close if server
end

Foxtrot

10/23/2010 2:07:00 AM

0

"5769 Dead, 912 since 1/20/09" <deadis@deadduz.com> wrote:

>Foxtrot wrote:
>
>> "Eddie Haskell" <fnbcj@adrt.com> wrote:
>>
>>>Subject: Post Your Favorite Hussein Lie
>>
>> Gitmo.
>
>A pity the Republicans are such pathetic cowards.
>
>"Oh, we're Americans! We're far too weak and fragile to let those
>terrible terrorists into our federal prisons! They're much smarter and
>stronger than us, and will get out and rape our garbage cans!"
>
>Meanwhile, Obama is still trying to close Gitmo, despite your cowardice
>and the fact that you sold out your citizenship.

Trying? What's stopping him? He's been in office for 21 months.
Closing it was a high priority when he was campaigning. But how often
do you hear him talking about it these days? He probably spends
more time on putting greens at lavish country clubs than he spends
trying to close Gitmo.

You passionately demanded that it be closed when Bush was in
office. But you have sold your soul to protect Obama and the rest
of the party.


Frank Pittel

10/24/2010 9:52:00 PM

0

In alt.politics.usa.republican 5769 Dead, 912 since 1/20/09 <deadis@deadduz.com> wrote:
: On Fri, 22 Oct 2010 19:07:08 -0700, Foxtrot wrote:

: > "5769 Dead, 912 since 1/20/09" <deadis@deadduz.com> wrote:
: >
: >>Foxtrot wrote:
: >>
: >>> "Eddie Haskell" <fnbcj@adrt.com> wrote:
: >>>
: >>>>Subject: Post Your Favorite Hussein Lie
: >>>
: >>> Gitmo.
: >>
: >>A pity the Republicans are such pathetic cowards.
: >>
: >>"Oh, we're Americans! We're far too weak and fragile to let those
: >>terrible terrorists into our federal prisons! They're much smarter and
: >>stronger than us, and will get out and rape our garbage cans!"
: >>
: >>Meanwhile, Obama is still trying to close Gitmo, despite your cowardice
: >>and the fact that you sold out your citizenship.
: >
: > Trying? What's stopping him? He's been in office for 21 months.

: He needs Congressional approval to relocate the prisoners, little right
: wing American coward. Why won't the cowards of the American right give
: that permission to him?

The looney tune brain dead lying fascist hate spewing loser lib dems had a
filibuster proof majority in congress. They could have passed anything they wanted
to pass and there would have been nothing the Republicans could have done to stop
them.

--




-------------------
Keep working dumbo needs the money