From nobody Wed Dec 15 11:47:27 2021 X-Original-To: freebsd-current@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 5960F18F22E2 for ; Wed, 15 Dec 2021 11:47:29 +0000 (UTC) (envelope-from SRS0=wFgk=RA=klop.ws=ronald-lists@realworks.nl) Received: from smtp-relay-int.realworks.nl (smtp-relay-int.realworks.nl [194.109.157.24]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4JDYQ86y6Kz3GQD for ; Wed, 15 Dec 2021 11:47:28 +0000 (UTC) (envelope-from SRS0=wFgk=RA=klop.ws=ronald-lists@realworks.nl) Date: Wed, 15 Dec 2021 12:47:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=klop.ws; s=rw2; t=1639568847; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=OUDSrgfOLrf9Fu/8tyZGy21gblJrnR4MKPNdyQup0rU=; b=vg8tp/IFKvp4jdBHuVNP4mv+jCRVXkZtjJE12jFUFnhqG9IvbZi4JmM9b47ekDXiU1SISe HE0bSy4WQ6TG4oNHt5ITOvPtANqHsI6nqJiq30jlLzwOcqdy0KrDYO7oEbtSGO7uB5wz+b oIT5s5w7orSerOnfvbhv+HOM9t4f0fM3xDt11b7CJ2N4jwOcuYOZUa8hML31LqeXFnMIZu +1npW5X1RdUDb6PPlwkpf5XC7alBBeqLryB/NDEHuIfLBAajmPdy7qEFVZtfw0NT4pdR07 Xd1wdbp6sWgrWzaFGxD0vLlspXvXYGbyZGxWenRt9I6JG71RLHf0z/blZm049w== To: Piper H Cc: freebsd-current@freebsd.org Message-ID: <1432797344.570.1639568847473@localhost> In-Reply-To: References: <1412287950.345.1639565502579@localhost> Subject: Re: question on socket server List-Id: Discussions about the use of FreeBSD-current List-Archive: https://lists.freebsd.org/archives/freebsd-current List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-current@freebsd.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_569_1908596974.1639568847444" X-Mailer: Realworks (588.193.3eeb293) Importance: Normal X-Priority: 3 (Normal) X-Rspamd-Queue-Id: 4JDYQ86y6Kz3GQD X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] Reply-To: ronald-lists@klop.ws From: Ronald Klop via freebsd-current X-Original-From: Ronald Klop X-ThisMailContainsUnwantedMimeParts: Y ------=_Part_569_1908596974.1639568847444 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit 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 Datum: woensdag, 15 december 2021 11:55 Aan: Ronald Klop 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 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 >> 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 >>> >>> >>> >> > ------=_Part_569_1908596974.1639568847444--