1
Hello, Currently I need to create a ruby connection using winapi only. Everything works perfectly, however, when the client sends an information, it needs EXACTLY ONE ANSWER, if there is no answer or there is more than one data sent by the server, it simply gets unstable(the ping goes up), I need it not to happen.
Here follows receive, send, and select, which I use to check for information for the client to read.
#----------------------------------------------------------------------------
# Checks waiting data's status.
#----------------------------------------------------------------------------
def select
result = Select.call 0, [1, @descriptor].pack('ll'), 0, 0, [0, 0].pack('ll')
SocketError.check if result == -1
return result
end
#----------------------------------------------------------------------------
# Checks if data is waiting.
#----------------------------------------------------------------------------
def ready?
return self.select != 0
end
#----------------------------------------------------------------------------
# Returns receieved data.
#----------------------------------------------------------------------------
def recv(length, flags = 0)
buffer = "\0" * length
result = Recv.call @descriptor, buffer, length, flags
SocketError.check if result == -1
return '' if result == 0
return buffer[0, result].unpack("c*").pack("c*") # gets rid of a bunch of \0
end
#----------------------------------------------------------------------------
# Sends data to a host.
#----------------------------------------------------------------------------
def send(data, flags = 0)
result = Send.call @descriptor, data, data.size, flags
SocketError.check if result == -1
p result
return result
end
It is worth remembering, that this happens only in WAN, in LAN the ping is stable(no, it is not the connection). Does anyone have any hint or solution?