Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using UNIX domain sockets

3 views
Skip to first unread message

listas.correo via beginners

unread,
Jan 15, 2024, 2:30:08 PMJan 15
to begi...@perl.org
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?
0 new messages