Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Socket: I don't get what is sent

by JaWi (Hermit)
on Oct 17, 2002 at 12:44 UTC ( #206005=note: print w/replies, xml ) Need Help??


in reply to Socket: I don't get what is sent

In your client, you should turn auto-flush on, by setting $| to a non-zero value. A snippet of how this would look like in your client code:
... # This message is print, so I do get here! # At the same tiome the server starts sending bars $|++; # <-- Turns on automatic flusing after each write... while (1) { $line = <SOCK>; print "\nGot1: ", $line; ...

Update: I've been playing with the code myself, and as tye pointed out in a reply below: you need to unbuffer the Client handle at server-side! This would make your server code look like this:

... $SIG{CHLD} = \&REAPER; for ( ; $paddr = accept(Client,Server); close Client) { # This will correctly set the autoflushing... select( ( select(Client), $|++ )[0] ); my($port,$iaddr) = sockaddr_in($paddr); my $name = gethostbyaddr($iaddr,AF_INET); ...
Success,

-- JaWi

"A chicken is an egg's way of producing more eggs."

Replies are listed 'Best First'.
(tye)Re: Socket: I don't get what is sent
by tye (Sage) on Oct 17, 2002 at 15:17 UTC

    $|++; # <-- Turns on automatic flusing after each write... No! That turns on automatic flushing after each write to STDOUT. Do one of the following:

    select( ( select(SOCK), $|++ )[0] ); # or use IO::Handle; SOCK->autoflush(1);
    Though I'm surprised that sockets don't default to being unbuffered.

            - tye (but my friends ca)
      Your right, the socket handle has to be unbuffered: however, this has to happen at server side and not client side...
      Funny however that the example in the perlipc doesn't mention this...

      -- JaWi

      "A chicken is an egg's way of producing more eggs."

Re: Re: Socket: I don't get what is sent
by Anonymous Monk on Oct 17, 2002 at 14:16 UTC
    Thanks to all of you, but this doen't work.
    I just tried all the suggestions:
    $|++; $|=1; in the Client and in the Server.
    But my Client keeps silence, doen't print anything as long the server is running.
    By the way all what has been sent is lost. I think if it were the buffer,
    it should print the buffer as soon as the first line: "Got1: NIX," appears.
    What happened to that what was written meanwhile to the buffer?
    Carl

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2022-08-16 13:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?