| 718 | } |
| 719 | |
| 720 | int Emotibit::create_data_connection () |
| 721 | { |
| 722 | int res = (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR; |
| 723 | for (int i = 2; i < 40; i += 2) |
| 724 | { |
| 725 | data_port = WIFI_ADVERTISING_PORT + i; |
| 726 | data_socket = new SocketClientUDP (ip_address.c_str (), data_port); |
| 727 | if (data_socket->bind () == ((int)SocketClientUDPReturnCodes::STATUS_OK)) |
| 728 | { |
| 729 | safe_logger (spdlog::level::info, "use port {} for data", data_port); |
| 730 | res = (int)BrainFlowExitCodes::STATUS_OK; |
| 731 | break; |
| 732 | } |
| 733 | else |
| 734 | { |
| 735 | safe_logger (spdlog::level::warn, "failed to bind to {}", data_port); |
| 736 | } |
| 737 | data_socket->close (); |
| 738 | delete data_socket; |
| 739 | data_socket = NULL; |
| 740 | } |
| 741 | return res; |
| 742 | } |
| 743 | |
| 744 | int Emotibit::create_control_connection () |
| 745 | { |