in reply to (podmaster) Re: Reading and writing sockets
in thread Reading and writing sockets

Hi,

The protocol is already fixed, where I am stuck is the logic I need to use to send AND receive commands and the same time. I need to be client AND server.

What loop do I need to create to handle both situations? Like:

if (!read_server_command && something_to_send) { send_command read_response } else { # handle server command send_response }
But how do I stop reading from a socket when I have to send something?

I hope you get the picture ;-)

Replies are listed 'Best First'.
Re: Re: (podmaster) Re: Reading and writing sockets
by PodMaster (Abbot) on Dec 11, 2001 at 14:57 UTC
    The protocol is already fixed... - who "fixed" it? who designed it? why? trying to remedy design flaws is a bad way to write programs.

    I need to be client AND server. - that's possible, but first you need to clearlyl define your protocol, as I haven't a clue as to what it is(send command, get response is not specific enough). How do you distinguish a command from a response?

    But how do I stop reading from a socket when I have to send something? - as far as I know, you can't. you wait till the socket times out. That is why you're supposed to read data in chunks, like in a while loop.
    read FILEHANDLE,SCALAR,LENGTH,OFFSET
    read FILEHANDLE,SCALAR,LENGTHwhile(read(FH,$rr,1024,$off){...

    I need to know more about what the actual protocol looks like.
     

    ____________________________________________________
    ** The Third rule of perl club is a statement of fact: pod is sexy.