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
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
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
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