Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 Dec 2021 20:13:46 +0800
From:      Piper H <potthua@gmail.com>
To:        Ronald Klop <ronald-lists@klop.ws>
Cc:        freebsd-current@freebsd.org
Subject:   Re: question on socket server
Message-ID:  <CA%2BGLnbjZXjhz3O2622fhr34z2FGcyjT_sE=uKi_FBwPEdvp_1g@mail.gmail.com>
In-Reply-To: <1432797344.570.1639568847473@localhost>
References:  <CA%2BGLnbiqXQDfMLovYgipiLjSvRSWk%2B1ukDrh779=zZDt3P2L7Q@mail.gmail.com> <1412287950.345.1639565502579@localhost> <CA%2BGLnbhqwAWJYDxO0MV27mXhvyqWBdPPnAVd6mfQdiNWvuvahA@mail.gmail.com> <1432797344.570.1639568847473@localhost>

next in thread | previous in thread | raw e-mail | index | archive | help
--00000000000090670e05d32e3d7b
Content-Type: text/plain; charset="UTF-8"

Thanks @Ronald Klop <ronald-lists@klop.ws>
I changed it to this and it does work:

        print "$str\015\012" or return;

Regards


On Wed, Dec 15, 2021 at 7:47 PM Ronald Klop <ronald-lists@klop.ws> wrote:

> Hi,
>
> Your program first waits for the first client to connect. So nothing is
> written anywhere.
> You can check by running "nc -v localhost 6666" in another terminal.
> After the first client disconnects it keeps looping in the while and the
> print will return 0 which means failure.
>
> Something like this will improve things.
>
>         if (0 == print "test\015\012") {
>                 return;
>         }
>
>
> Regards and happy hacking,
> Ronald.
>
> PS: I think this does not have to do a lot with freebsd-current. Might
> move it to https://lists.freebsd.org/subscription/freebsd-perl or some
> generic perl forum/ML.
>
>
>
> *Van:* Piper H <potthua@gmail.com>
> *Datum:* woensdag, 15 december 2021 11:55
> *Aan:* Ronald Klop <ronald-lists@klop.ws>
> *CC:* freebsd-current@freebsd.org
> *Onderwerp:* Re: question on socket server
>
> But I write this program to listen on port 6666 who sends a random str to
> the socket every 0.25 second. And there is no client connecting to the
> port. The server just runs there without problem. :( So I am not sure
> enough...
>
> use strict;
>
> package MyPackage;
> use base qw(Net::Server);
>
>
> my @fruit=qw(
> ...
> );
>
>
> sub process_request {
>     my $self = shift;
>     $| = 1;
>     my $max = scalar @fruit;
>
>     while (1) {
>         my $id1 = int(rand($max));
>         my $str = $fruit[$id1];
>
>         print "$str\015\012";
>         select(undef, undef, undef, 0.25);
>     }
> }
>
> MyPackage->run(port => 6666, ipv => '*');
>
> On Wed, Dec 15, 2021 at 6:51 PM Ronald Klop <ronald-lists@klop.ws> wrote:
>
>> Hi,
>>
>> Just try it!
>>
>> I think you will get an error that you are writing to a not-connected
>> socket.
>> From "man 2 write":
>> "     [EPIPE]            An attempt is made to write to a socket of type
>> SOCK_STREAM that is not connected to a peer socket."
>>
>> See also "man 2 send"  and "man 2 socket" for a lot more information.
>>
>> So it depends a bit on the type of socket you created.
>>
>> Regards and happy hacking,
>> Ronald.
>>
>>
>>
>> *Van:* Piper H <potthua@gmail.com>
>> *Datum:* woensdag, 15 december 2021 07:52
>> *Aan:* freebsd-current@freebsd.org
>> *Onderwerp:* question on socket server
>>
>> Hello
>>
>> I have little knowledge about socket programming.
>> I have a question that, if I have made a socket server, listening on a
>> port. The server prints data to the socket, but there is never a client
>> connection to the port, and the data is never consumed. What will happen
>> to
>> the server then? will the OS kernel be flushed by junk bytes?
>>
>> Thanks for your help.
>> Piper
>> ------------------------------
>>
>>

--00000000000090670e05d32e3d7b--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CA%2BGLnbjZXjhz3O2622fhr34z2FGcyjT_sE=uKi_FBwPEdvp_1g>