From nobody Wed Dec 15 12:13:46 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 ECF4D18F700C for ; Wed, 15 Dec 2021 12:13:58 +0000 (UTC) (envelope-from potthua@gmail.com) Received: from mail-ua1-x933.google.com (mail-ua1-x933.google.com [IPv6:2607:f8b0:4864:20::933]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JDZ0k633qz3L8H for ; Wed, 15 Dec 2021 12:13:58 +0000 (UTC) (envelope-from potthua@gmail.com) Received: by mail-ua1-x933.google.com with SMTP id o1so40554338uap.4 for ; Wed, 15 Dec 2021 04:13:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fOcV4HFq/MGeo8wLmASVHYK8748+uFw67hEi7cFjI/g=; b=CmJgRNRHvZGVLfnuLXykvRzsEBGqUjqZ62ycEiHiCVVzWZTzheSdWx1xCaU4hMYYtA fmAhekL+GAQddpe+S1kHAz2qKnQ7RXFAbh6Ol93WjgFbKvBx8nrWvPZHwkXqf7xUit0O zTwKNAT6cW8Iod2Q0cIekYo80PHLcuO7tflpHPfMCQqYaoafrUly0RfP4zMm0gZfuqPW UHZGq8PPEA1Xn21XbJ58hl/bsjWX2aFNOG5niKIHvWCr9yc5x4TsBFztUg/bSm95S06e lNvTPArgdbJwtspCwh+mQntPTw2q7DNYGwmaWSdFa3qDfy2qvzPsB6AGaS3EniX9upst vk4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fOcV4HFq/MGeo8wLmASVHYK8748+uFw67hEi7cFjI/g=; b=KvAXSskQwTN2ZD1cWeicohqzSWwYe5FjI9djB1esacBdNqap36/SARjVLD3RCciM1W T5nqWoZOdwjbuEY33VkopVRuB/UQcUB4++M0oVI/b5eHFPI531Vowhwh1xMSjIUChQ5x OtEyVam12XPMdAeFCp+RnvKFBjHvDeieVnxB7S8N6tMTTcXT0XuaPbNqGoTly8Frmaw9 nUuCJ+EpD5YP34wOALMvhpfZ8ymyfZFD8W0WCnf4rSqLLs3OOjDdfg/of6A+H6QXXO6n 22f8GdLDWlwjCCPak3q331GFmIxZcu7wl8sPp18xZArsSRmyLmkcDuR9jkaPBdW68q41 yYyQ== X-Gm-Message-State: AOAM532Cwh5sfAUxDqUfPoVTVDItUcPizOH4dNx2SRWHIT4Rc6r+hja7 LHFIhjgliG5kBlqqoxljezkptllCauVs1WftOSfDWqEUSfisnkWt X-Google-Smtp-Source: ABdhPJyx74hM+hXkvVqtaNBRKbbAfa+C6K5eyxj71TE11GDBHg/S4LKrivW63ulF8WwMIkbXH0whlFDZ44dVaHNVjkY= X-Received: by 2002:ab0:55ce:: with SMTP id w14mr9113932uaa.93.1639570438382; Wed, 15 Dec 2021 04:13:58 -0800 (PST) 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 References: <1412287950.345.1639565502579@localhost> <1432797344.570.1639568847473@localhost> In-Reply-To: <1432797344.570.1639568847473@localhost> From: Piper H Date: Wed, 15 Dec 2021 20:13:46 +0800 Message-ID: Subject: Re: question on socket server To: Ronald Klop Cc: freebsd-current@freebsd.org Content-Type: multipart/alternative; boundary="00000000000090670e05d32e3d7b" X-Rspamd-Queue-Id: 4JDZ0k633qz3L8H X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-ThisMailContainsUnwantedMimeParts: Y --00000000000090670e05d32e3d7b Content-Type: text/plain; charset="UTF-8" Thanks @Ronald Klop 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 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 > *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 >> ------------------------------ >> >> --00000000000090670e05d32e3d7b--