> For the complete documentation index, see [llms.txt](https://trialkey.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trialkey.gitbook.io/docs/api-reference/methods/addlistener.md).

# AddListener

## Description

Adds a listening socket that will accept connections

{% hint style="info" %}
**Good to know:** If you are creating a server that will accept connections from client (such as a web server) then you can use this method to start your application listening.
{% endhint %}

## Remarks

Call this method to start listening for a connection request on a particular port.

| Param          | Description                                                                                                                                                                             |
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| PortToListenOn | Port to listen on                                                                                                                                                                       |
| Protocol       | One of the [SSQ\_PROTOCOL](/docs/api-reference/constants/sq_protocol.md) constants (must be SQ\_TCPIP---SQ\_UDP is currently unsupported and is included for future extensibility only) |

When a client attempts to connect to an application that has called the AddListener method, the listening application's ConnectionRequest event will fire, allowing the application to accept or reject the connection. Note that the return value of this method is the SocketHandle for the listening socket, and this handle must be used to close the socket (via the CloseSock method). If the call fails with a return value of INVALID\_SOCKET (-1), use the [LastSockErr](/docs/api-reference/properties/lastsockerr.md) property to get the error number (these are standard Winsock errors). Note that when this socket is closed, a ConnectionTerminated event will fire.

## Prototype

LONG CSockQ::AddListener(long PortToListenOn, INT Protocol, long AdapterNumber, long Backlog)
