280
Platforms
©2000-2008 Tibbo Technology Inc.
which the connection is being originated must match the port defined by the
property. To achieve this, set the
= 1-
PL_SOCK_INCONMODE_SPECIFIC_IPPORT.
Here is an example of how to only accept incoming TCP connections from host
192.168.100.40 and port 1000:
sock.protocol= PL_SOCK_PROTOCOL_TCP
sock.inconmode= PL_SOCK_INCONMODE_SPECIFIC_IPPORT
sock.targetip=
"192.168.1.40"
sock.targetport=
1000
The sock object rejects an incoming connection by sending out a reset TCP packet.
This way, the other host is instantly notified of the rejection. There is an exception
to this -- see
Socket Behavior in the HTTP Mode
.
Listening ports
Ports on which your socket will accept an incoming connection are called "listening
ports". These are defined by two properties: the
. Notice that both properties are of string type, so each one can
accept a list of ports.
For example, to accept a normal data connection either on port 1001, port 2000,
or port 3000, set the sock.localportlist= "1001,2000,3000". Once the connection is
in progress, you can check which of the socket's local ports is actually engaged in
this connection. This is done through the
read-only property.
For UDP connections, the sock.localportlist is all there is. For TCP, which can be
used for "plain vanilla data connections" or for HTTP, you have another property-
sock.httpportlist. To be accepted by your socket, an incoming TCP connection has
to target either one of the ports on the sock.localportlist, or one of the ports on the
sock.httpportlist. The socket will automatically switch into the HTTP mode if the
connection is accepted on one of the ports from the sock.httpportlist.
Here is an example:
sock.localportlist =
"1001,2000"
sock.httpportlist =
"80"
The above means that any incoming TCP connection that targets either port 1001
or port 2000 will be interpreted as a regular data connection. If connection target
port 80 it will be accepted as an HTTP connection.
And what if the same port is listed both under the sock.localportlist and sock.
httpportlist?
sock.localportlist =
"1001,2000,80"
sock.httpportlist =
"80"
In this example, if there is an incoming connection targeting "our" port 80 and the
protocol is TCP then the mode will be HTTP- the sock.httpportlist has priority over
sock.localportlist. Of course, for UDP the sock.httpportlist won't matter since the
360
338
318
339
335
338