Groups | Search | Server Info | Login | Register


Groups > perl.beginners > #19353

Using UNIX domain sockets

Newsgroups perl.beginners
Message-ID <e011bddd-8d9f-4fa2-866c-6849c7e37ebb@yahoo.es> (permalink)
Date 2024-01-15 20:25 +0100
Subject Using UNIX domain sockets
References <e011bddd-8d9f-4fa2-866c-6849c7e37ebb.ref@yahoo.es>
From beginners@perl.org ("listas.correo" via beginners)

Show all headers | View raw


Hi,

I am trying to control mpv player using unix sockets but it looks like 
that perl is unable to send the string correctly.

I run the following command:
mpv --input-ipc-server=~/mpv.sock --idle=yes -v -v

If I sent the string using system commands:

$ echo '{"command":["stop"]}' | socat - ~/mpv.sock | jq
{
   "data": null,
   "request_id": 0,
   "error": "success"
}

It works as expected and is accepted by mpv:
[ipc_1] Client connected
[cplayer] Run command: stop, flags=64, args=[flags=""]
[ipc_1] Client disconnected


Now I run this perl code:

#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket::UNIX;

my $mpv_socket = IO::Socket::UNIX->new(
     Type    => SOCK_STREAM(),
     Peer    => "$ENV{HOME}/mpv.sock",
) or die "socket failed: ",$!,"\n";

my $cmd='{"command":["stop"]}';
$mpv_socket->send($cmd);

and it fails to send the correct text:
[ipc_2] Client connected
[ipc_2] Client disconnected
[ipc_2] Ignoring unterminated command on disconnect.

the message "Ignoring unterminated command on disconnect" is because the 
text sent does not seem to be correct and is ignored by mpv.

For what reason could it be that the text sent does not end correctly?

Back to perl.beginners | Previous | Next | Find similar


Thread

Using UNIX domain sockets beginners@perl.org ("listas.correo" via beginners) - 2024-01-15 20:25 +0100

csiph-web