On this page
  1. socket.htons
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

socket.htons

Prev: socket.htonl | Up: socket | Next: socket.if_indextoname
Rel: socket.AddressFamily, socket.close, socket.create_connection, socket.create_server
Ref: docs.python.org — socket.htons
Tags: #public #python3 #stdlib #socket


Import

import socket
from socket import htons

Signature & Overview

socket.htons(integer, /)

Convert a 16-bit unsigned integer from host to network byte order.

Usage

import socket

# Host-to-network 16-bit unsigned integer byte-order conversion
net = socket.htons(8080)
assert socket.ntohs(net) == 8080

Gotchas

REPL Inspect

from socket import htons
help(htons)

Linked from

Related notes