9.17 Client object

Description

You can establish a connection to other computers via the TCP/IP protocol with the Client object. If a connection has been established successfully then you call it a socket. Using such a socket you can send/receive data. In DestinyScript there are two kinds of sockets (= socket types): sockets using the Destiny protocol (= DestinySockets) and such who don't have a specific protocol (= RAW sockets). Sockets that are not longer required should be closed. The Client object requires an index to specify the responded socket. This index is in the range of 0 to 31. The assignment of the index can be done with the Server object if you accept incoming connections.

List of methods/properties

NameTypeShort description
TypePropertyThe used socket type
StatePropertyThe current connection state
LocalIPPropertyThe used ip of the own computer
LocalPortPropertyThe used port of the own computer
RemoteIPPropertyThe used ip of the other computer
RemotePortPropertyThe used port of the other computer
ConnectMethodEstablishes a connection to an other computer
CloseMethodCloses an open connection
SendVariableMethodSends a variable over a DestinySocket
SendByteMethodSends a byte over a DestinySocket
SendWordMethodSends a word over a DestinySocket
SendDwordMethodSends a dword over a DestinySocket
SendDoubleMethodSends a double over a DestinySocket
SendStringMethodSends a string over a DestinySocket
SendSwitchMethodSends a switch over a DestinySocket
SendRawDataMethodSends data over a RAW socket
GetRecvTypeMethodReturns the kind of received data from a DestinySocket
GetRecvLengthMethodReturns the number of bytes received on a socket
RecvIDMethodReceives the id from the current data package of a DestinySocket
RecvVariableMethodReceives a variable from a DestinySocket
RecvByteMethodReceives a byte from a DestinySocket
RecvWordMethodReceives a word from a DestinySocket
RecvDwordMethodReceives a dword from a DestinySocket
RecvDoubleMethodReceives a double from a DestinySocket
RecvStringMethodReceives a string from a DestinySocket
RecvSwitchMethodReceives a switch from a DestinySocket
RecvRawDataMethodReceives data from a RAW socket

Type

Description

This property specifies whether DestinySocket (= 0) or a RAW socket (= 1) is used. You can use the socket type constants for this.

Syntax

1
Client[Index].Type

Data type

Dword

Type

Property, read-only

Example

1
2
$
v[1] = Client[0].Type

State

Description

This property represents the current state of the socket. You can use the socket state constants for this.

Syntax

1
Client[Index].State

Data type

Dword

Type

Property, read-only

Example

1
2
$
v[1] = Client[0].State

LocalIP

Description

The value of this property is the ip used on the own computer for the connection.

Syntax

1
Client[Index].LocalIP

Data type

String

Type

Property, read-only

Example

1
2
$
a[1] = Client[0].LocalIP

LocalPort

Description

The value of this property is the port used on the own computer for the connection.

Syntax

1
Client[Index].LocalPort

Data type

Dword

Type

Property, read-only

Range

1 to 65535

Example

1
2
$
v[1] = Client[0].LocalPort

RemoteIP

Description

The value of this property is the ip used on the other computer for the connection.

Syntax

1
Client[Index].RemoteIP

Data type

String

Type

Property, read-only

Example

1
2
$
a[1] = Client[0].RemoteIP

RemotePort

Description

The value of this property is the port used on the other computer for the connection.

Syntax

1
Client[Index].RemotePort

Data type

Dword

Type

Property, read-only

Range

1 to 65535

Example

1
2
$
v[1] = Client[0].RemotePort

Connect

Description

You can establish a connection with this method using the the TCP/IP protocol. If you call this method you define whether it uses a DestinySocket or a RAW socket. Because the windows function used to establish a connection is a "blocking call" the DestinyScript (and even the game) will freeze until a connection is established or the timeout occured. The timeout value is ca. 2 seconds. If a connection has been established or not can be checked with the state property of this object.

Syntax

1
Client[Index].Connect(Address, Port, Sockettype)

Return value

None

Type

Method

Parameter: Address

Description

The address of the destination computer. This can either be an ip (e. g. "192.168.1.1") or a hostname (e. g. "bananen-joe.de").

Data type

String

Parameter: Port

Description

The port of the destination computer. (e. g. Port 80 for http)

Data type

Dword

Range

1 to 65535

Parameter: Sockettype

Description

The socket type for the connection. This can be either DestinySocket (= 0) or RAW socket (= 1). You can use the socket constants for this.

Data type

Dword

Range

0 to 1

Example

1
2
$
Client[0].Connect("bananen-joe.de", 80, SOCK_RAW)
At the end a connection via internet whould be established to the webserver "bananen-joe.de".

Close

Description

With this method an open connection can be closed. If a socket is closed it can be used to open a new connection. If you close a already closed socket this doesn't raise any problems.

Syntax

1
Client[Index].Close()

Return value

None

Type

Method

Example

1
2
$
Client[0].Close()

SendVariable

Description

With this method you can send a variable over a connected DestinySocket. This method can't be used with RAW sockets.

Syntax

1
Client[Index].SendVariable(ID, Variable)

Return value

None

Type

Method

Parameter: ID

Description

The index of the variable. This value may differ from the real variable index.

Data type

Dword

Parameter: Variable

Description

The value of the variable.

Data type

Dword

Example

1
2
$
Client[0].SendVariable(1, v[1])
At the end the value of the first variable whould be send over the first socket (which is a connected DestinySocket).

SendByte

Description

With this method you can send a byte over a connected DestinySocket. This method can't be used with RAW sockets.

Syntax

1
Client[Index].SendByte(ID, Byte)

Return value

None

Type

Method

Parameter: ID

Description

The associated index of the byte.

Data type

Dword

Parameter: Byte

Description

The value of the byte.

Data type

Byte

Example

1
2
$
Client[0].SendByte(1, v[1])
At the end the value of the first variable whould be send (as byte) over the first socket (which is a connected DestinySocket).

SendWord

Description

With this method you can send a word over a connected DestinySocket. This method can't be used with RAW sockets.

Syntax

1
Client[Index].SendWord(ID, Word)

Return value

None

Type

Method

Parameter: ID

Description

The associated index of the word.

Data type

Dword

Parameter: Word

Description

The value of the word.

Data type

Word

Example

1
2
$
Client[0].SendWord(1, v[1])
At the end the value of the first variable whould be send (as dword) over the first socket (which is a connected DestinySocket).

SendDword

Description

With this method you can send a dword over a connected DestinySocket. This method can't be used with RAW sockets.

Syntax

1
Client[Index].SendDword(ID, Dword)

Return value

None

Type

Method

Parameter: ID

Description

The associated index of the dword.

Data type

Dword

Parameter: Dword

Description

The value of the dword.

Data type

Dword

Example

1
2
$
Client[0].SendDword(1, d[1])
At the end the value of the first dword whould be send over the first socket (which is a connected DestinySocket).

SendDouble

Description

With this method you can send a double over a connected DestinySocket. This method can't be used with RAW sockets.

Syntax

1
Client[Index].SendDouble(ID, Double)

Return value

None

Type

Method

Parameter: ID

Description

The associated index of the double.

Data type

Dword

Parameter: Double

Description

The value of the double.

Data type

Double

Example

1
2
$
Client[0].SendDouble(1, f[1])
At the end the value of the first double whould be send over the first socket (which is a connected DestinySocket).

SendString

Description

With this method you can send a string over a connected DestinySocket. The string may not exceed a length of 255 chars. This method can't be used with RAW sockets.

Syntax

1
Client[Index].SendString(ID, String)

Return value

None

Type

Method

Parameter: ID

Description

The associated index of the string.

Data type

Dword

Parameter: String

Description

The value of the string. This value may not exceed 255 chars!

Data type

String

Example

1
2
$
Client[0].SendString(1, a[1])
At the end the value of the first string whould be send over the first socket (which is a connected DestinySocket).

SendSwitch

Description

With this method you can send a switch over a connected DestinySocket. This method can't be used with RAW sockets.

Syntax

1
Client[Index].SendSwitch(ID, Switch)

Return value

None

Type

Method

Parameter: ID

Description

The associated index of the switch.

Data type

Dword

Parameter: Switch

Description

The value of the switch.

Data type

Switch

Example

1
2
$
Client[0].SendSwitch(1, s[1])
At the end the value of the first string whould be send over the first socket (which is a connected DestinySocket).

SendRawData

Description

With this method you can send a specified amount of data over a RAW socket. The data is processed binary, so it is possible to send less data than the value contains (e. g. you can send 4 bytes of a double although it is usually 8 bytes long). This method can't be used with DestinySockets.

Syntax

1
Client[Index].SendRawData(Datasource, Length)

Return value

None

Type

Method

Parameter: Datasource

Description

The data source where the bytes are taken from.

Data type

Alle

Parameter: Length

Description

The number of bytes being send. This may not exceed the length of the data source. For example you can't send 9 bytes from a double (which has a maximum length of 8 bytes).

Data type

Dword

Example

1
2
3
4
$
a[1] = "GET / HTTP/1.0" + CRLF +
"Host: bananen-joe.de" + CRLF + CRLF;
Client[0].SendRawData(a[1], String.Length(a[1]))
At the end content of a[1] (which is a http request header) whould be send over a RAW socket (compare the example of connect) to the webserver "bananen-joe.de".

GetRecvType

Description

With this method you can determine whether a data packet has been received completely. If the return value is negative value then the data paket isn't complete (the return value is the negative data type), otherwise (if the return value is positive) the data paket is complete and the return value tells you what kind it is. You can use the data type constants for this. If there is no data paket this method will return 0. This method can only be used with DestinySockets. If you call this method the Destiny.dll will receive data on this socket if possible.

Syntax

1
Client[Index].GetRecvType()

Return value

Dword

Type

Method

Example

1
2
$
v[1] = Client[0].GetRecvType()
Am Ende wäre v[1] der Data type des zuletzt empfangenen Datenpakets bei einem verbundenen DestinySocket. Wenn Examplesweise der andere Computer mit SendVariable eine Variable versendet hätte, würde hier die Zahl 1 (= TYPE_VARIABLE) zurückgegeben werden.

GetRecvLength

Description

Returns the number of received data (in bytes). This value can't be more than 500 bytes due to a weakness of the Destiny.dll (the internal buffer is limited to 500 bytes). This method can be used with each socket type. If you call this method the Destiny.dll will receive data on this socket if possible.

Syntax

1
Client[Index].GetRecvLength()

Return value

Dword

Type

Method

Example

1
2
$
v[1] = Client[0].GetRecvLength()

RecvID

Description

Receives the associated id of the current data package. This method must be called implicitly before other recv methods are called on DestinySockets (except for GetRecvType and GetRecvLength) because these methods remove the current data package from the internal buffer. RecvID doesn't remove the current data package from the internal buffer. This method can only be used with DestinySockets.

Syntax

1
Client[Index].RecvID()

Return value

Dword

Type

Method

Example

1
2
$
v[1] = Client[0].RecvID()
At the end v[1] whould contain the id of the last received data package on a connected DestinySocket. For example if the other computer executes SendVariable(1, 2) this method (on our computer) whould return 1.

RecvVariable

Description

Receives the variable value of the current data package and removes that data package from the internal buffer. This method can only be used with DestinySockets.

Syntax

1
Client[Index].RecvVariable()

Return value

Dword

Type

Method

Example

1
2
$
v[1] = Client[0].RecvVariable()
At the end v[1] whould contain the variable value of the last received data package on a connected DestinySocket. For example if the other computer executes SendVariable(1, 2) this method (on our computer) whould return 2.

RecvByte

Description

Receives the byte value of the current data package and removes that data package from the internal buffer. This method can only be used with DestinySockets.

Syntax

1
Client[Index].RecvByte()

Return value

Byte

Type

Method

Example

1
2
$
v[1] = Client[0].RecvByte()

RecvWord

Description

Receives the word value of the current data package and removes that data package from the internal buffer. This method can only be used with DestinySockets.

Syntax

1
Client[Index].RecvWord()

Return value

Word

Type

Method

Example

1
2
$
v[1] = Client[0].RecvWord()

RecvDword

Description

Receives the dword value of the current data package and removes that data package from the internal buffer. This method can only be used with DestinySockets.

Syntax

1
Client[Index].RecvDword()

Return value

Dword

Type

Method

Example

1
2
$
v[1] = Client[0].RecvDword()

RecvDouble

Description

Receives the double value of the current data package and removes that data package from the internal buffer. This method can only be used with DestinySockets.

Syntax

1
Client[Index].RecvDouble()

Return value

Double

Type

Method

Example

1
2
$
f[1] = Client[0].RecvDouble()

RecvString

Description

Receives the string value of the current data package and removes that data package from the internal buffer. This method can only be used with DestinySockets.

Syntax

1
Client[Index].RecvString()

Return value

String

Type

Method

Example

1
2
$
a[1] = Client[0].RecvString()

RecvSwitch

Description

Receives the switch value of the current data package and removes that data package from the internal buffer. This method can only be used with DestinySockets.

Syntax

1
Client[Index].RecvSwitch()

Return value

Switch

Type

Method

Example

1
2
$
a[1] = Client[0].RecvSwitch()

RecvRawData

Description

Receives a specified amount of bytes and returns this value as a specified data type. If the data type has a minimum length (e. g. double requires 8 bytes total) the missing bytes will be filled with zeros. Finally the received amount of bytes will be removed from the internal buffer. The amount of bytes may not exceed 500 bytes. This method can only be used with RAW sockets.

Syntax

1
Client[Index].RecvRawData(DataType, Length)

Return value

Depends on the parameter DataType.

Type

Method

Parameter: DataType

Description

Defines the data type used for the return value. You can use the data type constants for this.

Data type

Dword

Range

1 to 7

Parameter: Length

Description

Defines the number of bytes to receive. If this value is too small for the specified data type then the missing bytes will be filled with zero bytes.

Data type

Dword

Range

1 to 500

Example

1
2
3
$
v[1] = Client[0].GetRecvLength();
a[1] = Client[0].RecvRawData(TYPE_STRING, v[1])
At the end a[1] whould contain a string in the length of the received bytes of the connected RAW socket. Usally there must be checked whether more than 0 bytes are received before the call of RecvRawData.