accept

Typecommand
DictionaryLCS
LibraryLiveCode Script
Syntax
accept [datagram] connections on port <portNumber> with message <callbackMessage>
Summary

Accepts an internet connection and creates a socket for that connection.

Introduced1.0
OSmac, windows, linux, ios, android
Platformsdesktop, server, mobile
Parameters
NameTypeDescription
callbackMessage

The name of a message to be sent when a connection is made or a datagram is received.

portNumber

The TCP port number on which to accept connections.

Example
accept connections on port 80 with message "connectionMade"
accept datagram connections on port 80 with message "connectionMade"
on mouseUp
   accept connections on port 80 with message "connectionMade"
end mouseUp

on connectionMade pIPAddress
   put "Connection made:" && pIPAddress
end connectionMade
accept connections on port 0 with message "connectionMade"
put it into tPort
Values
NameTypeDescription
It

The actual port that was bound. In the case of accepting connections on port 0 the operating system will assign a free port in its ephemeral port range.

The result

An error message if the socket could not be opened.

RelatedProperty: HTTPProxy, script, defaultNetworkInterface
Command: read from socket, write to socket, close socket, open socket
Function: openSockets, hostAddressToName, hostName, hostAddress, peerAddress, hostNameToAddress
Glossary: datagram, IP address, TCP, port, command, socket, UDP, host, server, message, parameter, process, object
Securitynetwork
Description

Use the accept command when running a server, to accept TCP connections or UDP datagrams from other systems (or other processes on the same system). Use the datagram option if you want to accept UDP datagrams.

When a connection is made or a datagram is received, the accept command creates a new socket that can be used to communicate with the other system (or process). When using the close socket, read from socket, or write to socket commands, you can refer to this socket with a socket identifier that looks like this: host:port[|connectionID]

where the connectionID is a number assigned by the accept command. (You only need to specify the connection number if there is more than one socket connected to a particular port and host.)

The callbackMessage is sent to the object whose script contains the accept command. Either one or two parameters are sent with this message. The first parameter is the IP address of the system or process making the connection. If a datagram is being accepted, the second parameter is the contents of the datagram.

Note: The defaultNetworkInterface property can be used to specify the interface to accept connections on.

Tagsnetworking