in reply to Socket response inconsistent
You're also doing strange things with the return value of select -- it returns an array of 3 array refs (read/write/error), or an empty array. In your code, the $read variable ends up with the length of the array in it, and you die if select returned an empty array. This works, but you'd probably be better off making $read an array, both for clarity and so you can do something meaningful with it if the select doesn't time out.
I'm not sure why you're getting the varying behavior -- on my box it's very consistent (select returns me a handle ready to read every time if I throw packets at an IP address with a live box on it; timeouts every time if it's a dead address). You are sending your packets to localhost, which may have something to do with it. If what you're trying to do is check for a response from the server you're throwing these packets at, you'll want to add a recv in there after the select to see what, if anything, the server sent back.
It's been a long time since I did anything with UDP, so I may be a little off here and there. You might find it enlightening to pick up a good TCP/IP networking book and read up on the guts of this stuff. Knowing what's supposed to happen behind the scenes makes this sort of debugging a lot easier.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Socket response inconsistent
by agoth (Chaplain) on Jul 31, 2001 at 19:08 UTC | |
by Cubes (Pilgrim) on Jul 31, 2001 at 19:45 UTC |