TWSocketServer Last Updated: 09/27/2001 |
TWSocketServer is derived from TWSocket which has many properties and methods. Not all are used by the server, only the necessary ones are listed here.
Here are the sections available for the TWSocketServer:
- [ Properties ]
- [ Events ]
- [ Methods ]
- [ Examples ]
Below is the full description for all the sections in the TWSocketServer:
Below is a list of all Properties for use as a quick reference:
Below is a list of all Properties with their complete descriptions:
Addr: | The interface to listen on if it is a multi homed computer or '0.0.0.0' for all interfaces. |
[Return to Top] | |
MultiThreaded: | Set this to true if you use TWSocketServer in a thread. Then it uses his own message pump. |
[Return to Top] | |
Port: | The port where it has to listen on. |
[Return to Top] | |
Terminated: | If you use TWSocketServer in NO FORMS, and you have assigned your own message pump in OnMessagePump, then you have to set Terminated to True if you application terminates. |
[Return to Top] | |
ClientClass: | If you derive your own TClient from TWSocketClient then you have to assign it to this property before calling Listen. |
[Return to Top] | |
ClientCount: | The amount of clients currently connected. If you read ClientCount in the OnClientDisconnect you have to decrement it with one. |
[Return to Top] | |
Client: | Client[Index: integer] Gives direct access to any client. Index is zero based. |
[Return to Top] | |
Banner: | The banner send to the client as welcome message. |
[Return to Top] | |
BannerToBusy: | The banner send to the client if you have set MaxClients and when that limit is exceeded. |
[Return to Top] | |
MaxClients: | Set it to 0 for unlimited count of clients. |
[Return to Top] | |
Below is a list of all Events for use as a quick reference:
Below is a list of all Events with their complete descriptions:
OnBgException: | This is fired when a background exception occur. TWSocket works completely in background using corporative multitasking. This means event driven using messages. If some exception should occur form the middle of nowhere (the message pump) then this event is fired. Because you can not be sure when a background exception occur that the server is still working fine, you can eventually set the CanClose parameter to True, and in the OnSessionClosed you can post a message to re-listen again. |
[Return to Top] | |
OnChangeState: | TWSocketServer has following states: wsInvalidState, wsOpened, wsAccepting, wsListening, wsClosed. Every time state is changed this event is fired. You can use it to log or display information. |
[Return to Top] | |
OnError: | If you don't wants to handle exceptions yourself then you can assign code to this event. As a good programming rule however you have to handle your code in a try / except block and handle the exceptions yourself in the except part of it. |
[Return to Top] | |
OnMessagePump: | If you use TWSocketServer with NO FORMS then you can use either call MessageLoop or ProcessMessages to quickly build a working message pump. Or you may build your own custom message pump tailored to your needs. Your message pump must set TWSocketServer.Terminated property to TRUE when your application terminates or you may experience long delays when closing your application. You must assign it at run-time before using the component. If there's nothing assigned to it TWSocketServer will call automatically his own MessagePump. |
[Return to Top] | |
OnSessionClosed: | Is called when the socket is closed. This is the place to let it automatically re-listen (by posting a message) if needed. |
[Return to Top] | |
OnClientCreate: | Is called right after creation of the client (ClientClass). If you want to attach the Client to a thread then this is the place to create your tread, resume it and wait until it's running. If you use a threaded client then you have to call ThreadAttach in the Execute method (see TWSocket help). |
[Return to Top] | |
OnClientConnect: | This is the place to assign the necessary events to the ClientClass, and do the various property settings you need. |
[Return to Top] | |
OnClientDisconnect: | Is called right before the ClientClass is destroyed. If you have attached the Client to a thread this is the place to terminate the thread. |
[Return to Top] | |
Below is a list of all Methods for use as a quick reference:
Below is a list of all Methods with their complete descriptions:
Close: | procedure Close; Closes the Server. |
[Return to Top] | |
Listen: | procedure Listen; Start the server. You have to assign Addr and Port properties every time before calling it. |
[Return to Top] | |
MessagePump: | procedure MessagePump; Calling this method will fire OnMessagePump if assigned, or will call his own ProcessMessages if not assigned |
[Return to Top] | |
MessageLoop: | procedure MessageLoop; You can use this to quickly build a working message pump. It loop tru message processing until the WM_QUIT message is received. This is intended for multithreaded application using TWSocket. MessageLoop is different from ProcessMessages because it actually block if no message is available. The loop is broken when WM_QUIT is retrieved. |
[Return to Top] | |
ProcessMessage: | function ProcessMessage: Boolean; This function is very similar to TApplication.ProcessMessage. You can also use it if your application has no TApplication object (Forms unit not referenced at all). |
[Return to Top] | |
ProcessMessages: | procedure ProcessMessages; You can use this to quickly build a working message pump. It loop thru message processing until all messages are processed. This function is very similar to TApplication.ProcessMessage. This is intended for multithreaded application using TWSocket. You can also use it if your application has no TApplication object (Forms unit not referenced at all). |
[Return to Top] | |
Below is a list of all Examples for use as a quick reference:
Below is a list of all Examples with their complete descriptions:
Example1: | for n := 0 to Infinity do if Socket.HelpReady then break; |
[Return to Top] | |