Ruby Winapi Socket TCP / IP

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 AN ANSWER, if there is no response or there is more than one data sent by the server, it simply gets unstable (ping goes up), I need this not to happen .

Here follows the receive, send, and select, which I use to check if there is 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 = "
  #----------------------------------------------------------------------------
  # 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 = "%pre%" * 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 %pre%
  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
" * 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 %pre% 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

Remember that this happens only in WAN, in LAN the ping is stable (no, it is not the connection). Does anyone have any tips or solutions?

    
asked by anonymous 16.05.2015 / 02:26

0 answers