Igo Leonardo
Igo Leonardo

Reputation: 13

Remote UDP Socket don't receive the packets

i created two files with udp socket programming, an sends and other receive, i did put the file that receive in another computer with different provider, i executed the sender and after the receiver, i did see that the receiver no received no packets, the ip configuration it's ok, the sender send's to receiver IP and port, some guys said that i need "open" the udp port, but the MMORPG Games use this strategy, is this necessary? the receiver do the Bind() on your IP and Defined Port, see the code.

Sender:

begin
    sender = UDPSocket.new()
    host   = "10.100.1.115"
    port   = 3001
  while true
    p "Enviando..."
    sender.send("Numero #{10}",0,host,port)
    sleep 0.1
  end
  rescue
    p $!
  end
gets

Receiver:

begin
    myIP = IPSocket.getaddress(Socket.gethostname) # => 10.100.1.115
    puts "Seu IP => #{myIP}"
    sock = UDPSocket.new()
    sock.bind(myIP,3001)
    puts "#=========================#"
    puts "....Esperando Pacotes....."
    puts "#=========================#"
    while true
     line = sock.recvfrom(1024)
     puts "Recebido : #{line}"
    end
  rescue
    p $!
  end
  gets

Is something wrong? I need use the NAT?, if yes, how i use? what the commun strategy use for game developers to make a client socket udp receive the send packets by server computer?

(Sorry, my english is bad, i know).

Upvotes: 1

Views: 643

Answers (1)

Intrepidd
Intrepidd

Reputation: 20858

If the other computer is behind a router or a NAT, configuration must be done on the router to forward the packets to the actual computer.

Upvotes: 1

Related Questions