Difference between revisions of "TWSocketServer"

From Overbyte
Jump to navigation Jump to search
Line 1: Line 1:
[[Main_Page | Main page]] -> [[ICS_Components_Reference | ICS component reference]] -> [[TWSocketServer]]
+
[[Main_Page | Main page]] -> [[ICS_Components_Reference | ICS component reference]] -> [[TWSocketServer]] and [[TSslWSocketServer]]
  
 
== Overview ==
 
== Overview ==
Line 11: Line 11:
 
TWSocketServer will normally be used to listen on a given TCP port. When a client connects, it will instantiate a new TWSocketClient component to handle communication with client. Normally you will derive your own component from TWSocketClient to add private data and methods to handle your processing needs. You tell TWSocketServer which component class it has to instantiate using ClientClass property. You have to initialize each instance created to handle each client from OnClientConnect event handler. TWSocketServer maintain a list of connected clients. You can access it using Client[] indexed property. ClientCount property is the size of Client[] array.
 
TWSocketServer will normally be used to listen on a given TCP port. When a client connects, it will instantiate a new TWSocketClient component to handle communication with client. Normally you will derive your own component from TWSocketClient to add private data and methods to handle your processing needs. You tell TWSocketServer which component class it has to instantiate using ClientClass property. You have to initialize each instance created to handle each client from OnClientConnect event handler. TWSocketServer maintain a list of connected clients. You can access it using Client[] indexed property. ClientCount property is the size of Client[] array.
  
Since it is derived from [[TWSocket]], lots of properties and events are unused and not listed here. Properties and events that have a meaning in both server or client component are listed here.
+
Since it is derived from [[TWSocket]] and [[TSslWSocket]], lots of properties and events are unused and not listed here. Properties and events that have a meaning in both server or client component are listed here.
  
 
Note that TWSocketServer is only usable for incoming TCP connections. Use [[TWSocket]] if you need to use UDP.
 
Note that TWSocketServer is only usable for incoming TCP connections. Use [[TWSocket]] if you need to use UDP.

Revision as of 16:43, 14 November 2018

Main page -> ICS component reference -> TWSocketServer and TSslWSocketServer

Overview

unit OverbyteIcsWSocketS.pas
inheritance TWSocket

TWSocketServer will normally be used to listen on a given TCP port. When a client connects, it will instantiate a new TWSocketClient component to handle communication with client. Normally you will derive your own component from TWSocketClient to add private data and methods to handle your processing needs. You tell TWSocketServer which component class it has to instantiate using ClientClass property. You have to initialize each instance created to handle each client from OnClientConnect event handler. TWSocketServer maintain a list of connected clients. You can access it using Client[] indexed property. ClientCount property is the size of Client[] array.

Since it is derived from TWSocket and TSslWSocket, lots of properties and events are unused and not listed here. Properties and events that have a meaning in both server or client component are listed here.

Note that TWSocketServer is only usable for incoming TCP connections. Use TWSocket if you need to use UDP.

Note: When a TWSocketClient is closed, it automatically frees itself. With a normal TWSocket, the programmer is responsible for freeing the object.

Properties

Addr Server listen IP address, IPv4 or IPv6, maybe 0.0.0.0 or :: to listen on all available addresses, ignored if any IcsHosts specified. IP address must exist and not be in use elsewhere for the same port.
Banner A short message line sent when each client connects.
BannerTooBusy A short message sent when a client connects and the number of clients already exceeds the MaxClients limit.
Client Indexed property giving access to all connected clients.
ClientClass Class the component use to handle each incoming connection.
ClientCount Number of connected clients.
Handle Handle of the hidden window used for socket operation.
HSocket Underlying winsock socket handle.
IcsHosts Allows one or more TIcsHosts to be set, as TIcsHostCollection, an alternate way for specifying multiple listeners that allows multiple hosts to be specified, each with one or two IP addresses and non-SSL and SSL port bindings, SSL certificates and private key (perhaps combined in a bundle), SSL context and security level, and other web server host related properties (used by higher level components). Each IcsHost has one or more HostNames to which it will recognise, that can share IP addresses.
LastError Last error which occurred.
ListenBacklog How many pending connection the system has to accept before denying access.
MaxClients Max number of connected client. All subsequent connections will be closed.
Port TCP port or service name to listen to.
PortNum Readonly property with numeric value corresponding to Port.
Proto Protocol used. Must be 'tcp'.
State Gives the state of the component.

Methods

Abort Abort current asynchronous operation.
Close Stops listening, does not disconnect connected clients.
CloseDelayed Same as Close however it's executed delayed, after current event has finished.
Create Create a new instance of the component.
Destroy Destroy the current instance.
IsClient Check if a component reference is one of the connected clients.
Listen Start accepting connections.
MessageLoop Internal message loop.
MessagePump Internal message pump.
ProcessMessage Process a single message.
ProcessMessages Process messages until message queue is empty.
Release Destroy the current instance after the current event is terminated.
ThreadAttach Detach from current thread.
ThreadDetach Attach to current thread.

Events

OnBgException When a background exception occurs.
OnChangeState When the component state changes.
OnClientConnect When a new client is connecting.
OnClientCreate When a new client component instance is created.
OnClientDisconnect When a client disconnects.
OnError When an error occurs. Better to use exception handling.
OnMessagePump To call your own external message pump instead of built-in one.

How to



ICS Components Reference