views:

165

answers:

2

This might be the most stupid thing i've ever seen, i had a broken pipe error with the method send and the ruby class 'Socket', i had this thing 4 days ago and didn't find any thing about it, and i'm kind of going crazy.

I'm almost desperate, i found a broken pipe errors at the internet, but non of them with the send method, or even with the class socket. my code goes like this:

require 'socket'
sock = Socket.open(Socket::PF_INET,Socket::SOCK_STREAM,Socket::IPPROTO_TCP)
@data = "anyThing"
@addr = pack_sockaddr_in(port, host)
sock.send(@data, 0, @addr)

any help pleas ...

A: 

perhaps the other end is closing the connection?

Justin
nop ... but thanx any way.
Raafat
+2  A: 

Correct me if I'm wrong, but maybe you need to actually connect to your host before sending data? I see you creating a TCP socket, but no actual connection formed... Does this code work?

require 'socket'
sock = Socket.open(Socket::PF_INET,Socket::SOCK_STREAM,Socket::IPPROTO_TCP)
@data = "anyThing"
@addr = pack_sockaddr_in(port, host)
sock.connect(@addr)    #make the connection
sock.send(@data, 0)

Source: http://www.rubycentral.com/pickaxe/lib%5Fnetwork.html

You may also want to try using the TCPSocket class. I haven't used any of this Ruby code, so I'm not used to this particular library; please let me know if I got this all wrong. ;)

require 'socket'
sock = TCPSocket.new(host, port)
@data = "anyThing"
sock.send(@data, 0)
Twisol
dude ... u just made my day, thanx a lot.well 4 the TCPSocket class i already used it before, but i'm writing the socket this way 4 a reason.and by the way your code is absolutely right, thanx again.
Raafat
Sure thing! Glad I could help :D
Twisol