Skip to main content
Open topic with navigation CAPL Functions » TCP/IP API » OnTcpListen

OnTcpListen

Valid for: CANoe DE • CANoe4SW DE

Function Syntax

void OnTcpListen( dword socket, long result)

Method Syntax

Method Syntax
void OnTcpListen( TcpSocket socket, long result);

Description

If the CAPL program implements this callback it is called when TcpListen was called and a connection request for the specified socket is received. The connection must be accepted with TcpAccept because the listen socket otherwise remains blocked for other clients. This block is evident for a client in OnTcpConnect from the output of error code 10061 (Connection refused).

Parameters

  • socket: The socket handle or socket object. If the handle is valid (not equal to ~0), it corresponds to the socket that was used for TcpListen.
  • result: The specific result code of the operation. If the operation completed successfully the value is zero. Otherwise the value is an error code.

Return Values

Example

// ---------------------------------------------------
// Callback when client connects to server's listen socket.
// ---------------------------------------------------
void OnTcpListen( dword socket, long result)
{
  dword newSocket;
  newSocket = TcpAccept( socket );
  if (newSocket != ~0)
  {
    // start to receive data on the new socket...
  }
  else
  {
    writeLineEx( 1, 3, "S: TcpAccept: Socket error: %d", IpGetLastSocketError(socket) );
  }
}
Create TCP Client and Server Sockets