Overview


When attempting to connect a device through the BioStar 2 Device SDK, the connection may fail with errors such as BS_SDK_ERROR_CANNOT_LISTEN_SOCKET, BS_SDK_ERROR_CANNOT_CONNECT_SOCKET, BS_SDK_ERROR_TIMEOUT, or BS_SDK_ERROR_SOCKET_IS_NOT_CONNECTED.


These errors may occur when initializing or connecting a device using the BioStar 2 Device SDK sample code, or when running your own application built with the Device SDK.


They are usually caused by environmental or configuration issues. This article explains the most common causes of these connection failures and provides solutions to help you resolve them.


For details on return codes, refer to this link: https://kb.supremainc.com/bs2sdk/doku.php?id=en:return_code


Case 1. Another application uses port 51212 or 51213.



Cause

The Device SDK cannot create a socket connection because the required port (51212 or 51213) is already occupied by another application, such as BioStar 2.


The BioStar 2 Device SDK communicates with devices using specific ports. By default, the Device SDK uses port 51212 for communication and 51213 for secure communication. These are predefined by the Device SDK and cannot be changed. If another application such as BioStar 2 is already using these ports, the SDK cannot establish a connection to the device.


Possible reasons

  • BioStar 2 Software is running. The BioStar 2 Software uses the same 51212 and 51213 port as the Device SDK, which can block the Device SDK from connecting to the device.
  • Another application or process is already using port 51212 or 51213.


Solution

  • Stop BioStar 2 services before running the Device SDK application.

  • Turn off the other program using the 51212 or 51213 port. If you see a "LISTENING" status for port 51212 or 51213, the port is already in use. Check which process is using the port:
    netstat -ano | findstr :51212
    netstat -ano | findstr :51213

    tasklist /svc /FI "PID eq [PID]" // Show process and service linked to the PID


Case 2. Cannot connect to the device



Cause

The connection may fail when the Device SDK is unable to reach the device due to a network issue, an incorrect connection mode, or because the device is already connected to another application.


Possible reasons

  • The device is powered off, disconnected, or not on the network.
  • The device is already connected to another application.
  • When the Connection Mode is set differently from the intended use case.


The "Server to Device" refers to the scenario where the Device SDK initiates the connection to the devices, and the "Device to Server" refers to the scenario where the devices initiate the connection to the server. The default connection mode of a device is the "Server to Device".


Solution

  • Ping the device to verify it's reachable: ping [Device IP]
  • The device cannot be connected to multiple servers. For example, if the device is already connected to BioStar 2, it cannot accept additional connections until it is released. Please disconnect the device from another server.
  • Please check that the Connection Mode is configured correctly for its intended purpose. The Connection Mode can be configured in the device settings. For example, if the server is requesting a connection to the device, the [Server to Device] mode should be configured on the device.


Case 3. The device has an SSL certificate configured with another server



Cause

SSL handshake failed between the server and the device due to a certificate mismatch.


Possible reasons

  • When the server and the device certificates do not match.
  • When an SSL communication is required but the device lacks an SSL certificate, or vice versa.


Solution

  • Upload a valid certificate that matches the SSL communication requirements, or perform a Factory Default to remove the existing certificate on the device. (Press 'n' to the SSL configuration in the first screen of the sample code).


Case 4. SSL configuration mismatch



Cause

The device and the Device SDK use different communication modes (SSL vs. non-SSL). If SSL communication is enabled on the device (and an SSL certificate has been issued), the application must establish an SSL connection that matches the device’s configuration.


Possible reasons

  • The device is configured to use SSL communication, but the Device SDK attempts to connect without SSL enabled, or vice versa.


Solution

  • Perform a Factory Default to remove the existing certificate on the device.
  • When the server and the device are configured with the same SSL certificate, communication between them should be established over SSL.
  • If you want to stop using SSL communication, connect to the device through SSL and then call BS2_DisableSSL to remove the SSL certificate from the device. (Press 'y' to the SSL configuration in the first screen of the sample code). 
  • After deleting the certificate, reconnect to the device using non-SSL communication.