Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server (Not)   Client   Old   Guides   Examples
New in version: 6.3   6.4   6.5   7.0   7.1   7.2   7.3   7.4   7.5   8.0    Statistic  

Socket.Listen

Binds the socket to the port and starts listening.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
Socket 3.1 Yes Yes Yes Yes Yes

MBS( "Socket.Listen"; SocketID; Port )

Parameters

Parameter Description Example value
SocketID The socket ID received by Socket.Connect function. $sock
Port The port number to listen at. 8000

Result

Returns OK or error message.

Description

Binds the socket to the port and starts listening.
For UDP Socket, the socket starts receiving packets.
For TCP Socket, the socket can accept connections which causes a script to be called. You set the script name with Socket.SetNewConnectionHandler. In the script you call Socket.AcceptNewConnection to get a new socket for the new connection.

Be aware that FileMaker Server does not allow the plugin to operate if no script is running. So if you use sockets there, make sure a script is running or paused while you expect an answer coming in.

Examples

Listen to a given Port:

Set Variable [$r; Value:MBS("Socket.Listen"; $$sock; 12345)]

Create TCP Socket listening on a port:

Set Variable [$$sock; Value:MBS("Socket.NewTCPSocket")]
If [MBS("IsError")]
    Show Custom Dialog ["Failed to create Socket"; $$sock]
    Exit Script []
End If
Set Variable [$r; Value:MBS("Socket.SetNewConnectionHandler"; $$sock; Get(FileName); "NewConnection")]
Set Variable [$r; Value:MBS("Socket.SetErrorHandler"; $$sock; Get(FileName); "SocketError")]
Set Variable [$r; Value:MBS("Socket.Listen"; $$sock; TCP Receiver::ListenPort)]
If [MBS("IsError")]
    Show Custom Dialog ["Failed to create Socket"; $$sock]
    Exit Script []
End If

See also

Example Databases


Socket.LastMessagePort   -   Socket.LocalIP

Feedback: Report problem or ask question.




Links
MBS Xojo tutorial videos