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?

  • All the same, it would be a good idea to look at the code in which you are requesting a connection and trying to get an answer, and not this garbage: Console.WriteLine("Service response: " + e.Data); - Bulson
  • Bulson, I had to rephrase my question in a new way in a different way. Here is a link to the new branch. Stackoverflow.com/questions/740716/… - ismdmr

0