11from __future__ import annotations
22import json
3- import os
4- import sys
5- import socket
63from typing import Optional
7-
84import numpy as np
95import zmq
10- from qtpy .QtCore import QObject , QThread , Signal
11-
12-
13- DEFAULT_TCP_PORT = 5556
6+ from qtpy .QtCore import QObject , Signal
7+ from ._utils import default_endpoint
148
159
1610class ZMQImageListener (QObject ):
@@ -77,15 +71,6 @@ def _teardown(self):
7771 self .status .emit ("Listener stopped." )
7872
7973
80- def default_endpoint (public : bool = False ) -> str :
81- if public :
82- return f"tcp://{ _preferred_ip ()} :{ DEFAULT_TCP_PORT } "
83- if os .name == "nt" : # Windows: prefer TCP
84- return f"tcp://127.0.0.1:{ DEFAULT_TCP_PORT } "
85- # Unix: fast local IPC
86- return "ipc:///tmp/napari_stream.sock"
87-
88-
8974def bind_endpoint_for_public (endpoint : str ) -> str :
9075 """Convert a TCP endpoint to bind on all interfaces."""
9176 if not endpoint .startswith ("tcp://" ):
@@ -101,18 +86,6 @@ def bind_endpoint_for_public(endpoint: str) -> str:
10186 return f"tcp://*:{ port_int } "
10287
10388
104- def _preferred_ip () -> str :
105- """Best-effort guess of a non-loopback IPv4 address for sharing endpoints."""
106- try :
107- infos = socket .getaddrinfo (socket .gethostname (), None , family = socket .AF_INET )
108- for _ , _ , _ , _ , (addr , * _rest ) in infos :
109- if not addr .startswith ("127." ):
110- return addr
111- except Exception :
112- pass
113- return "127.0.0.1"
114-
115-
11689def _from_bytes (buf : bytes , meta : dict ) -> np .ndarray :
11790 """Reconstruct ndarray from raw bytes and metadata.
11891
0 commit comments