NetSocket
Represents a network socket.
Summary
Methods
Method | Returns |
---|---|
Connect(target: string, port: int) | int |
Read(length: int) | (string, int) |
Write(data: string) | (int, int) |
Destroy() | int |
ReadFrom(length: int, host: string, port: int) | (string, string, int, int) |
WriteTo(data: string, host: string, port: int) | (int, int) |
Methods
Connect
Connect(target: string, port: int): int
Attempts to establish a connection to the specified target at the specified port. Returns a status code. Status code 0
indicates the operation completed successfully while any other number represents an error. For a complete listing of error codes refer to the Windows Sockets Error Codes table on MSDN.
Parameters
Name | Type | Description |
---|---|---|
target | string | The target host or IP address. |
port | int | The port to establish the connection to. |
Returns
Type | Description |
---|---|
int |
Read
Read(length: int): (string, int)
Attempts to read data from the socket. Returns the data and a status code. The length of the returned data will not necessarily be the same as the requested data length.
Parameters
Name | Type | Description |
---|---|---|
length | int | The number of bytes to read. |
Returns
Type | Description |
---|---|
string | |
int |
Write
Write(data: string): (int, int)
Writes data to the socket. Returns the number of bytes written and a status code.
Parameters
Name | Type | Description |
---|---|---|
data | string | The data to write to the socket. |
Returns
Type | Description |
---|---|
int | |
int |
Destroy
Destroy(): int
Terminates the connection (if active) and destroys the underlying socket. Returns a status code.
Returns
Type | Description |
---|---|
int |
ReadFrom
ReadFrom(length: int, host: string, port: int): (string, string, int, int)
Attempts to read a datagram. Returns the data, the source ip, source port, and a status code. The length of the returned data will not necessarily be the same as the requested data length.
Parameters
Name | Type | Description |
---|---|---|
length | int | The number of bytes to read. |
host | string | The remote hostname or IP address. |
port | int | The remote port. |
Returns
Type | Description |
---|---|
string | |
string | |
int | |
int |
WriteTo
WriteTo(data: string, host: string, port: int): (int, int)
Sends data to the specified destination. Returns the number of bytes written and a status code.
Parameters
Name | Type | Description |
---|---|---|
data | string | The data to write to the socket. |
host | string | The remote hostname or IP address. |
port | int | The remote port. |
Returns
Type | Description |
---|---|
int | |
int |