Issue.
BS2_Intialize returns BS2_SDK_ERROR_CANNOT_LISTEN_SOCKET(-103) error
Environment.
It was okay until the SDK 2.4.x but the issue happens with SDK 2.5.0 or higher version
Cause.
The server listening port is duplicated with other program. For example, BioStar 2 SW is using the server port(Device->Server mode) 51212 as default. SDK server port is set to 51212 as well. Since SDK 2.5.0, SDK will be shut down if the listening port is used by another program.
Solution.
Change the server port using the API BS2_SetServerPort.
Sample code
The order is GetServerPort ->SetServerPort -> Initial
int delayTerminate = 0; UInt16 port = BS2Environment.BS2_TCP_SERVER_PORT_DEFAULT; BS2ErrorCode result = (BS2ErrorCode)API.BS2_GetServerPort(sdkContext, out port); if (result != BS2ErrorCode.BS_SDK_SUCCESS) { Console.WriteLine("GetServerPort: Got error({0}).", result); ClearSDK(delayTerminate); return; } Console.WriteLine("What server port number will you use in IPv4? [{0} Default]", port); Console.Write(">>>> "); port = Util.GetInput((UInt16)port); result = (BS2ErrorCode)API.BS2_SetServerPort(sdkContext, port); if (result != BS2ErrorCode.BS_SDK_SUCCESS) { Console.WriteLine("SetServerPort: Got error({0}).", result); ClearSDK(delayTerminate); return; }
The changed port is below.
*.If you want to use the port instead of another port, set the server port function when starting the server.