Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Socket response inconsistent

by Cubes (Pilgrim)
on Jul 31, 2001 at 18:08 UTC ( [id://101156]=note: print w/replies, xml ) Need Help??


in reply to Socket response inconsistent

I'm not sure what you're trying to do here. You say you're trying to test the success of sending a UDP message, but you don't check the return value of your send. Even if you do check that, it's not going to tell you anything about the server on the other end. UDP is an unreliable, connectionless protocol -- you'll find out whether or not your bits went out on the wire, nothing more.

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
    The sending of the UDP message has been consistently ok, if I print the return of send that's consistent and fine.

    The point of the script is to test the status of the server at the other end, when it receives a UDP message goes off and does stuff and returns a UDP response.

    I dont want to go ahead and check recv unless the IO::Select has a consistent and checkable response, but even if i turn $read into a proper array, it doesn't help much.

    Points taken on your box does it, I'll check versions, and have been looking out for a TCP/IP book for a while, time to bite the bullet, cheers :)

      When I did a recv after getting something back from select, I consistently got empty (i.e. zero byte) responses. Though I'm not entirely sure what is supposed to happen here, this does make some kind of sense to me -- select is saying "yeah, the socket's there, go ahead and read from it," even though there is no data presently waiting.

      As for books, I highly recommend UNIX Network Programming by W. Richard Stevens, and Douglas Comer's Internetworking with TCP/IP (Vol. I covers the basic, low-level stuff). Not exactly light bedtime reading, but they will give you a solid understanding of what lies beneath all these slick perl modules.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://101156]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-09-07 21:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.