Re: Question about sockets/listeners
- From: Francis Cianfrocca <garbagecat10@xxxxxxxxx>
- Date: Sat, 15 Dec 2007 12:12:07 -0500
[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.
.
- References:
- Question about sockets/listeners
- From: James Croft
- Question about sockets/listeners
- Prev by Date: Re: Work with Audio Files
- Next by Date: Re: Problem with using win32ole in Linux server.
- Previous by thread: Re: Question about sockets/listeners
- Next by thread: Splitting string into array keeping delimiters
- Index(es):
Relevant Pages
|