Re: Question about sockets/listeners



[Note: parts of this message were removed to make it a legal post.]

On Dec 15, 2007 9:38 AM, James Croft <crofty_james@xxxxxxxxxxx> wrote:

hi, i'm very new to ruby and so i'd be very grateful of any help on
this. I am writing a script that listens for UDP packets on a
particular port. This is very easy using 'socket'. I then want to make
a script that simulates lots of clients sending UDP packets to the
listener. These clients should send a UDP packet from a particular port
and then listen for a response on that same port. For this reason, I am
trying to run each simulated client in a different thread. A simplified
version of what i have done so far is shown below, however, when I run
this, the client stops sending packets after the 66th one. Can someone
explain this to me please? why is it stopping at 66? which limit am i
hitting?



Ok, I tweaked my test program somewhat:

#---------------------------------------
require 'rubygems'
require 'eventmachine'


EM.epoll

SERVER = "127.0.0.1"
PORT = 1500

module Server
def receive_data data
send_data "I saw your #{data}"
end
end

module Client
def post_init
@@counter ||= 0
@@counter += 1
send_datagram "Data packet #{@@counter}", SERVER, PORT
end
def receive_data data
@@received ||= 0
@@received += 1
p "Received #{@@received}: #{data}"
close_connection
end
end

EM.run {
EM.open_datagram_socket SERVER, PORT, Server

t = EM::PeriodicTimer.new(0.05) {
n = rand(1000) + 60000
EM.open_datagram_socket SERVER, n, Client
}
}


#-----------------------------

Now I'm delaying before opening each client as you were, and I'm using
random ports chosen in a high range. I'm also closing client sockets after
they receive their responses. This version is now up to 10,000 packets and
it's still running strong.

Also, on a Linux kernel, I took out the close_connection statement and used
EPOLL to eliminate Ruby's limit of 1024 descriptors per process. I had to
add a mechanism to keep the random port number generator from giving the
number of an already-open port. That program is also still running at well
over 10,000 open sockets and packets now.

.



Relevant Pages

  • Re: How port forwarding programs really work?
    ... So for each client you will can map a dedicated source port on the PF server that is used to handle the request/response between the PF and S for the specific client. ... - there's a computer 'S' on which some game server (or any server like ... like 1234 and waits for UDP packets. ...
    (microsoft.public.win32.programmer.networks)
  • How port forwarding programs really work?
    ... I'm trying to code a port forwarding program using raw sockets. ... like 1234 and waits for UDP packets. ... packet is coming directly from a client, ...
    (microsoft.public.win32.programmer.networks)
  • Re: Setting up a Windows VPN through a Fedora Linux gateway
    ... >>port redirection, ... The windows vpn is a client, ... > need for port forwarding at the client end. ... Then you can see what packets are going ...
    (comp.os.linux.networking)
  • Re: UDP on Windows 7/ Vista
    ... listens on some port for commands, one of the commands is to give updates to ... the client at a given rate to a given port. ... Vista too), we ran into the problem if the client is on the local host, it ... You can't sniff the localhost packets with wireshark. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Problem with writing fast UDP server
    ... > I wrote a simple case test: client and server. ... > packets within 0.137447118759 secs. ... I've used this script to test sending UDP packets. ... Uses port %d. ...
    (comp.lang.python)