whisker.socket

whisker/socket.py


Copyright © 2011-2020 Rudolf Cardinal (rudolf@pobox.com).

This file is part of the Whisker Python client library.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


Low-level network socket functions.

whisker.socket.get_port(x: str | int) int[source]

Works out an integer TCP/IP port number.

Parameters:

x – port number or name

Returns:

port number

Raises:
  • ValueError – bad value

  • TypeError – bad type

whisker.socket.socket_receive(sock: socket, bufsize: int = 4096) str[source]

Receives ASCII data from a socket and returns a string.

Parameters:
  • sock – TCP/IP socket

  • bufsize – buffer size

Returns:

data as a string

whisker.socket.socket_send(sock: socket, data: str) int[source]

Sends some of the data to a network socket, encoded via ASCII, and returns the number of bytes actually sent.

See https://stackoverflow.com/questions/34252273.

whisker.socket.socket_sendall(sock: socket, data: str) None[source]

Sends all the data specified to a network socket, encoded via ASCII.

See https://stackoverflow.com/questions/34252273.