9.18 Server object
Description
You can accept incoming connections from other computers via the TCP/IP protocol with the Server object. Accepted connections can be accessed via the
Client object.
List of methods/properties
Name | Type | Short description |
Type | Property | The used socket type |
State | Property | The current connection state |
Listen | Method | Waits for incoming connections |
Close | Method | Stops the waiting for incoming connections |
Accept | Method | Accepts an incoming connection |
Description
This property specifies whether accepted connections will be DestinySockets (= 0) or RAW-Sockets (= 1). You can use the
socket type constants for this. This value will be specified with the call of the
listen method.
Syntax
Data type
Dword
Type
Property, read-only
Example
Description
This property specifies the current state of the server socket. You can use the
socket state constants for this.
Syntax
Data type
Dword
Type
Property, read-only
Example
1
2
$
v[1] = Server].State
Description
With this method you can set the server socket into the listening state. If a server socket is in listening state then it can accept incoming connections. To accept an incoming connection you can use the
accept method. On some computers the firewall can make trouble. In this case it is impossible to accept incoming connections. Fore more specific information see at the
known bugs.
Syntax
1
Server.Listen(Port, SocketType)
Return value
None
Type
Method
Parameter: Port
Description
The local port used for incoming connections. The clients must connect to this port if they want to establish a connection.
Data type
Dword
Range
1 to 65535
Parameter: SocketType
Description
Data type
Dword
Range
0 to 1
Example
1
2
$
Server.Listen(12345, SOCK_DESTINY)
At the end incoming connections from the network (or internet) whould be able to accept.
Description
With this method you can close the server socket. In this case no more incoming connections will be accepted. Already connected clients are still connected.
Syntax
Return value
None
Type
Method
Example
Description
With this method you can accept an incoming connection (if there is one). The accepted connection will be dedicated to a
Client object. The return value of this method is the index used for the client object that has accepted the connection. If there wasn't an incoming connection pending then this method will return -1. You can specify a client with the parameter client. If you do so then only this client object will be used to accept a connection and the client socket will be closed if necessary. If the next free socket shall be used then you can use the
NEXT_FREE_SOCKET constant (= -1).
Syntax
Return value
Dword
Type
Method
Parameter: Client
Description
The index of the client object which shall accept the incoming connection. For the next free client object use the
NEXT_FREE_SOCKET constant.
Data type
Dword
Range
-1 to 31
Example
1
2
$
v[1] = Server.Accept(NEXT_FREE_SOCKET)
At the end v[1] whould contain the index of the client object which has accepted the incoming connection (if there was one). This only works if the server socket was in listening state. If a client has established a connection (and it has been accepted) then you can access this connection (in this example) with Client[v[1]] like a normal client socket.