It is required to write a small c # client that could interact with a third-party service using the WebSocket protocol. To accomplish this task, I use https://github.com/sta/websocket-sharp .
The whole point of the problem is that you need to call certain methods of the service, and process the results obtained. To process the return result of the method, I use the following code:
websocket.onMessage += (sender, e) => Console.WriteLine("Service response: " + e.Data); I call the methods in turn: method1() , method2() and method3() . Each of them returns a specific response from the service. This is where the problem arises, or rather, duplicates the responses received from these methods. In other words, the results of the execution of the methods are displayed several times in the console. Like that:
result1 \n result2 \n result2 \n result3 \n result3 \n result3
connect() called only once.
Please tell me what could be the problem? Maybe somehow you can clear the values obtained by onMessage?
Console.WriteLine("Service response: " + e.Data);- Bulson