# CreateSocketListener

## Description

Creates a socket listener that listens on a specified port for incoming socket connections. When a connection occurs it will be held in a queue until you retrieve it with GetSocketListenerConnection. If you want to reject a connection you must retrieve it and then delete it. The listener will continue accepting connections until it is deleted. If your device has multiple network interfaces then you can specify which one to listen on by using the IP address parameter. To listen on all interfaces use an empty string as the IP address.
If the device has both IPv4 and IPv6 addresses then the listener can only listen on one or the other, not both. To listen for both IPv4 and IPv6 connections you need to create two listeners, one for the IPv4 connections and one for the IPv6 connections. Connections from either will behave exactly the same after they are connected. To create an IPv6 listener pass an IPv6 IP address to CreateSocketListener, or "anyip6" to listen on any suitable IPv6 address. If you pass an empty string or "anyip4" as the IP address then it will listen for IPv4 connections.
You can have multiple listeners active at the same time, but they must all use different ports or IPs.
When choosing a port number you should avoid low values as these will frequently be used by other apps and services. If something is already listening on a port then your attempt to listen on it will fail. Returns 0 if it failed to start listening.

## Definition

integer CreateSocketListener( listenerID, szIP, port )

int agk::CreateSocketListener( UINT listenerID, const char *szIP, int port )

integer CreateSocketListener( szIP, port )

UINT agk::CreateSocketListener( const char *szIP, int port )

## Parameters

- listenerID - An ID to use to reference this listener in the future
- szIP - The IP address of the interface to listen on, can be IPv4 or IPv6, or "anyip4", or "anyip6"
- port - The TCP port to listen on, in the range 1025 to 65535