Home > Net >  Asp.net created WebSocket core, ClientWebSocket unable to send data connection fails
Asp.net created WebSocket core, ClientWebSocket unable to send data connection fails

Time:02-23

The server ASP.NET CORE NET (5.0)
Create a WebSocket: ws://localhost: 5000/ws1


Use the h5 link send everything is normal, if (context. Web sockets. IsWebSocketRequest) this is true on normal interaction

Send abnormal use desktop connection,
Using the component ClientWebSocket connect the if (context. Web sockets. IsWebSocketRequest) this is false cannot interact,
The code is as follows:
String strUrl="ws://127.0.0.1:5000/ws1";
String strMsg="Hello";
Byte [] bytMsg=Encoding. UTF8. GetBytes (strMsg);
ClientWebSocket CWS=new ClientWebSocket ();
CWS. ConnectAsync (new Uri (strUrl) System. The Threading. CancellationToken. None), Wait (0);//removed here wait also is same, error here
CWS. SendAsync (new ArraySegment (bytMsg), WebSocketMessageType. Text, true, System. Threading. CancellationToken. None);

CWS. CloseAsync (WebSocketCloseStatus NormalClosure, "1", System. Threading. CancellationToken. None).
CWS. The Dispose ();

In the solution!!!!!

CodePudding user response:


 


Await the CWS. ConnectAsync (new Uri (strUrl) System. The Threading. CancellationToken. None).








CodePudding user response:



Looked everywhere on the appearance, but the methods how to realize, individual writing?



[/code]

CodePudding user response:

The service side is also use asynchronous,
  •  Tags:  
  • C#
  • Related