IP*Works! Bluetooth - Online Help
Available for:
IP*Works! Bluetooth
Questions / Feedback?

BTDaemon Component

Properties   Methods   Events   Configuration Settings   Errors  

A Bluetooth server component based on a high-performance, asynchronous, event-driven architecture.

Syntax

nsoftware.IPWorksBT.Btdaemon

Remarks

The BTDaemon component implements a light-weight Bluetooth server. To begin listening for connections set Protocol and LocalPort, then set Listening to true. When a client connects the ConnectionRequest event will fire. If the incoming connection is accepted the Connected event will fire.

Once a connection is established the DataIn event will fire with data received from the client. To send data set DataToSend or call Send, SendLine, or SendFile.

Clients may be disconnected by calling Disconnect.

Threading in Server Applications

In .NET, all socket-based components perform all socket IO through asynchronous methods. Each call consumes a thread from the system's thread pool, and thus the number of concurrent calls is limited to the number of worker threads returned by System.Threading.ThreadPool.GetMaxThreads. When using several components that can each create a socket connection or a single component that can create multiple socket connections, the application may enter a state where all of the pool threads are in use for receiving. In a scenario such as this, the remote hosts may be waiting for data from the application before sending, but the application cannot send that data because all the threads are tied up waiting for inbound data. This is particularly important for server applications that use a daemon component.

For example, say a server application 'S' has a max thread pool size of three, and clients 'A' and 'B' connect to it and each client uploads a large file. After all uploads are complete, 'S' enqueues an asynchronous read request in the thread pool for each client. Since there is no work being done, the thread pool immediately consumes two threads which wait for any further data from 'A' and 'B'. While 'S' is still processing the first two files it has received, client 'C' connects and uploads a relatively small file. Similarly, once that upload has completed 'S' enqueues a third read request, and the thread pool immediately consumes the third and final thread to wait for further data from 'C'. Once 'S' completes processing any of the files it will enqueue a send request. However, since all three threads are in use and waiting for data from the clients, the send operation cannot be completed. The entire system becomes deadlocked because each of the clients is waiting for data from the server, which cannot send that data since all of its pool threads are in turn waiting for data from the clients.

To avoid a deadlock situation such as this, it is necessary to ensure that the maximum number of socket connections an application can make is always at least one less than the number of available worker threads. One method to achieve this is to call System.Threading.ThreadPool.SetMaxThreads during the application's startup to set the maximum number of threads to a value high enough to support the application for the duration of its execution. Another option is to trap an event such as ConnectionRequest and Disconnected from each component instance with logic to manage the max thread pool size according to the application's current needs.

Property List


The following is the full list of the properties of the component with short descriptions. Click on the links for further details.

ConnectionBacklogThe maximum number of pending connections maintained by the Bluetooth subsystem.
ConnectionsA collection of currently connected clients.
DefaultEOLA default EOL value to be used by incoming connections.
DefaultMaxLineLengthThe default maximum line length value for inbound connections.
DefaultSingleLineModeTells the component whether or not to treat new connections as line-oriented.
DefaultTimeoutAn initial timeout value to be used by incoming connections.
ListeningIf True, the component accepts incoming connections on LocalPort.
LocalHostThe address of the Bluetooth device through which connections are initiated or accepted.
LocalPortThe port in the Bluetooth device on which the component listens.
ProtocolThe Bluetooth protocol to be used.

Method List


The following is the full list of the methods of the component with short descriptions. Click on the links for further details.

ConfigSets or retrieves a configuration setting .
DisconnectDisconnect the specified client.
DoEventsProcesses events from the internal message queue.
InterruptInterrupts a synchronous send to the remote host.
SendSends data to the remote host.
SendFileSend file to the remote host.
SendLineSends a string followed by a newline.
ShutdownShuts down the server.

Event List


The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.

ConnectedFired immediately after a connection completes (or fails).
ConnectionRequestFired when a request for connection comes from a remote host.
DataInFired when data comes in.
DisconnectedFired when a connection is closed.
ErrorInformation about errors during data delivery.
ReadyToSendFired when the component is ready to send data.

Configuration Settings


The following is a list of configuration settings for the component with short descriptions. Click on the links for further details.

BTAuthenticateWhether authentication is required.
BTEncryptForces an encrypted connection if set to True.
BTMTUMaxThe maximum RFCOMM MTU (Maximum Transmission Unit).
BTDefaultMTUThe default RFCOMM MTU (Maximum Transmission Unit).
BTMTUMinThe minimum RFCOMM MTU (Maximum Transmission Unit).
CodePageThe system code page used for Unicode to Multibyte translations.

 
 
Copyright (c) 2016 /n software inc. - All rights reserved.
Build 1.0.6093.0