Skip to content

open_socket_acceptOpenSocketAcceptOpenSocketAcceptopen_socket_acceptT_open_socket_accept🔗

Short description🔗

open_socket_acceptOpenSocketAcceptOpenSocketAcceptopen_socket_acceptT_open_socket_accept — Open a socket that accepts connection requests.

Signature🔗

open_socket_accept( number Port, attribute.name GenParamName, attribute.value GenParamValue, out socket AcceptingSocket )void OpenSocketAccept( const HTuple& Port, const HTuple& GenParamName, const HTuple& GenParamValue, HTuple* AcceptingSocket )static void HOperatorSet.OpenSocketAccept( HTuple port, HTuple genParamName, HTuple genParamValue, out HTuple acceptingSocket )def open_socket_accept( port: int, gen_param_name: MaybeSequence[str], gen_param_value: MaybeSequence[Union[float, int, str]] ) -> HHandle

Herror T_open_socket_accept( const Htuple Port, const Htuple GenParamName, const Htuple GenParamValue, Htuple* AcceptingSocket )

void HSocket::HSocket( Hlong Port, const HTuple& GenParamName, const HTuple& GenParamValue )

void HSocket::HSocket( Hlong Port, const HString& GenParamName, const HString& GenParamValue )

void HSocket::HSocket( Hlong Port, const char* GenParamName, const char* GenParamValue )

void HSocket::HSocket( Hlong Port, const wchar_t* GenParamName, const wchar_t* GenParamValue ) (Windows only)

public HSocket( int port, HTuple genParamName, HTuple genParamValue )

public HSocket( int port, string genParamName, string genParamValue )

void HSocket::OpenSocketAccept( Hlong Port, const HTuple& GenParamName, const HTuple& GenParamValue )

void HSocket::OpenSocketAccept( Hlong Port, const HString& GenParamName, const HString& GenParamValue )

void HSocket::OpenSocketAccept( Hlong Port, const char* GenParamName, const char* GenParamValue )

void HSocket::OpenSocketAccept( Hlong Port, const wchar_t* GenParamName, const wchar_t* GenParamValue ) (Windows only)

void HSocket.OpenSocketAccept( int port, HTuple genParamName, HTuple genParamValue )

void HSocket.OpenSocketAccept( int port, string genParamName, string genParamValue )

Description🔗

open_socket_acceptOpenSocketAccept opens a socket that will accept incoming connection requests. This operator is the necessary first step in the establishment of a communication channel between two HALCON processes. The socket listens for incoming connection requests on the port number given by Portportport.

It is possible to specify a Portportport of 0, triggering implementation-defined behavior. On most operating systems, using a port number of 0 instructs the operating system to choose a free port randomly.

The following parameters can be set for GenParamNamegenParamNamegen_param_name.

  • 'protocol'"protocol": Specifies the protocol to be used. The 'HALCON'"HALCON" protocol without a specific address family, will use IPv4 or IPv6 automatically depending on the network configuration of the computer. To use a specific address family a ‘4’ or ‘6’ (for IPv4 or IPv6, respectively) must be appended to the name of the protocol. For example, 'HALCON4'"HALCON4" designates a HALCON connection over IPv4. Possible values for a generic socket communication are 'UDP'"UDP" and 'TCP'"TCP" which also support appended ‘4’ and ‘6’. Both communication partners must use the same protocol. To exchange data using generic sockets use send_dataSendData and receive_dataReceiveData only.

    Default: 'HALCON'"HALCON"

  • 'address'"address": Instructs the socket to accept only connection requests addressed to a specific address. This address is specified as either an IPv4 or IPv6 address in numerical form, or a hostname. For example, 'localhost'"localhost" would instruct the socket to accept only connections addressed to the address 'localhost'"localhost", which normally maps to the local loopback network interface '127.0.0.1'"127.0.0.1".

  • 'timeout'"timeout": Sets a timeout for this socket. The timeout is given in seconds or as the string 'infinite'"infinite". It is used especially as timeout and waiting mode in a following socket_accept_connectSocketAcceptConnect call with the parameter Waitwaitwait set to 'auto'"auto".

  • 'string_encoding'"string_encoding": Sets the string encoding that is expected when sending and receiving strings with this socket. It is used for send_tupleSendTuple and receive_tupleReceiveTuple as well as send_dataSendData and receive_dataReceiveData. When the protocol 'HALCON'"HALCON" is used, the setting only has effect on connections to HALCON versions prior to 18.11. If the connection partner is detected to have HALCON version 18.11 or newer, UTF-8 is used to encode tuples.

  • 'reuseaddr'"reuseaddr": Controls the setting of the socket option SO_REUSEADDR. When 'reuseaddr'"reuseaddr" is set to 'false'"false", SO_REUSEADDR will not be set. On Windows Systems, conflicting access on a single port will only be detected, when 'reuseaddr'"reuseaddr" is set to 'false'"false".

    Default: 'true'"true"

  • 'tls_enable'"tls_enable": Controls the use of Transport Layer Security (TLS) for the new Socket. When 'tls_enable'"tls_enable" is set to 'true'"true", the created socket will accept TLS secured connections only. Furthermore, both generic parameters 'tls_private_key'"tls_private_key" and 'tls_certificate'"tls_certificate" must be set, each with a path to the private certificate key and the path to the public server certificate. Private key and server certificate must be provided in PEM-format.

    Default: 'false'"false"

The accepting socket is returned in AcceptingSocketacceptingSocketaccepting_socket. open_socket_acceptOpenSocketAccept returns immediately without waiting for a request from another process, which must be initiated by calling open_socket_connectOpenSocketConnect. This allows multiple other processes to connect to the particular HALCON process that calls open_socket_acceptOpenSocketAccept. To accept an incoming 'HALCON'"HALCON" or 'TCP'"TCP" connection request, socket_accept_connectSocketAcceptConnect must be called to obtain a socket for the final communication.

Execution information🔗

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

This operator returns a handle. Note that the state of an instance of this handle type may be changed by specific operators even though the handle is used as an input parameter by those operators.

Parameters🔗

Portportport (input_control) number → (integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Port number.

Default: 30003000
Suggested values: 3000, 45703000, 4570
Value range: 1024 ≤ Port ≤ 65535
Minimum increment: 1
Recommended increment: 1

GenParamNamegenParamNamegen_param_name (input_control) attribute.name(-array) → (string)HTuple (HString)HTuple (string)MaybeSequence[str]Htuple (char*)

Names of the generic parameters that can be adjusted for the socket.

Default: [][]
List of values: 'address', 'protocol', 'string_encoding', 'timeout', 'tls_certificate', 'tls_enable', 'tls_private_key'"address", "protocol", "string_encoding", "timeout", "tls_certificate", "tls_enable", "tls_private_key"

GenParamValuegenParamValuegen_param_value (input_control) attribute.value(-array) → (string / real / integer)HTuple (HString / double / Hlong)HTuple (string / double / int / long)MaybeSequence[Union[float, int, str]]Htuple (char* / double / Hlong)

Values of the generic parameters that can be adjusted for the socket.

Default: [][]
Suggested values: 0, 3.0, 'infinite', 'HALCON', 'UDP', 'TCP', 'HALCON4', 'UDP4', 'TCP4', 'HALCON6', 'UDP6', 'TCP6', 'utf8', 'locale', 'ignore', 'true', 'false'0, 3.0, "infinite", "HALCON", "UDP", "TCP", "HALCON4", "UDP4", "TCP4", "HALCON6", "UDP6", "TCP6", "utf8", "locale", "ignore", "true", "false"

AcceptingSocketacceptingSocketaccepting_socket (output_control) socket → (handle)HTuple (HHandle)HSocket, HTuple (IntPtr)HHandleHtuple (handle)

Socket number.

Example🔗

(HDevelop)

* Process 1
dev_set_colored (12)
open_socket_accept (3000, [], [], AcceptingSocket)
* Busy wait for an incoming connection
dev_error_var (Error, 1)
dev_set_check ('~give_error')
OpenStatus := 5
while (OpenStatus != 2)
    socket_accept_connect (AcceptingSocket, 'false', Socket)
    OpenStatus := Error
    wait_seconds (0.2)
endwhile
dev_set_check ('give_error')
* Connection established
receive_image (Image, Socket)
threshold (Image, Region, 0, 63)
send_region (Region, Socket)
receive_region (ConnectedRegions, Socket)
area_center (ConnectedRegions, Area, Row, Column)
send_tuple (Socket, Area)
send_tuple (Socket, Row)
send_tuple (Socket, Column)
close_socket (Socket)
close_socket (AcceptingSocket)

* Process 2
dev_set_colored (12)
open_socket_connect ('localhost', 3000, [], [], Socket)
read_image (Image, 'fabrik')
send_image (Image, Socket)
receive_region (Region, Socket)
connection (Region, ConnectedRegions)
send_region (ConnectedRegions, Socket)
receive_tuple (Socket, Area)
receive_tuple (Socket, Row)
receive_tuple (Socket, Column)
close_socket (Socket)

Combinations with other operators🔗

Combinations

Possible successors

socket_accept_connectSocketAcceptConnect

See also

open_socket_connectOpenSocketConnect, close_socketCloseSocket, get_socket_paramGetSocketParam, set_socket_paramSetSocketParam, send_imageSendImage, receive_imageReceiveImage, send_regionSendRegion, receive_regionReceiveRegion, send_tupleSendTuple, receive_tupleReceiveTuple, send_dataSendData, receive_dataReceiveData

Module🔗

Foundation