44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
|
|
"""
|
||
|
|
MIDI over TCP/IP.
|
||
|
|
"""
|
||
|
|
|
||
|
|
import socket
|
||
|
|
from typing import Literal, overload
|
||
|
|
|
||
|
|
from .ports import BaseIOPort, MultiPort
|
||
|
|
|
||
|
|
class PortServer(MultiPort):
|
||
|
|
def __init__(self, host: str, portno: int, backlog: int = 1) -> None: ...
|
||
|
|
@overload
|
||
|
|
def accept(self, block: Literal[True] = True) -> SocketPort:
|
||
|
|
"""
|
||
|
|
Accept a connection from a client.
|
||
|
|
|
||
|
|
Will block until there is a new connection, and then return a
|
||
|
|
`SocketPort` object.
|
||
|
|
|
||
|
|
If `block=False`, `None` will be returned if there is no
|
||
|
|
new connection waiting.
|
||
|
|
"""
|
||
|
|
@overload
|
||
|
|
def accept(self, block: bool) -> SocketPort | None: ...
|
||
|
|
|
||
|
|
class SocketPort(BaseIOPort):
|
||
|
|
def __init__(self, host: str, portno: int, conn: socket.socket | None = ...) -> None: ...
|
||
|
|
|
||
|
|
def connect(host: str, portno: int) -> SocketPort:
|
||
|
|
"""Connect to a socket port server.
|
||
|
|
|
||
|
|
The return value is a `SocketPort` object connected to another
|
||
|
|
`SocketPort` object at the server end. Messages can be sent either way.
|
||
|
|
"""
|
||
|
|
|
||
|
|
def parse_address(address: str) -> tuple[str, int]:
|
||
|
|
"""Parse and address on the format host:port.
|
||
|
|
|
||
|
|
Returns a tuple (host, port). Raises ValueError if format is
|
||
|
|
invalid or port is not an integer or out of range.
|
||
|
|
"""
|
||
|
|
|
||
|
|
def format_address(host: str, portno: int) -> str: ...
|