Opening a websocket channel inside MVC controller

梦想的初衷 提交于 2019-12-03 23:04:45

Seems fine.

  • You probably want to change the while(true) to while (!HttpContext.RequestAborted.IsCancellationRequested) so you detect client disconnects and end the request.
  • You don't need to check for null or the state of the websocket after you call accept.

I'm assuming all of that code is temporary and you'll actually be reading something from the websocket.

All the usual websocket rules apply:

  • Use SSL (when you're hosting it forreal)
  • It won't work on multiple servers (it's a point to point socket connection)
  • You need to support handling partial frames. You can punt this if you know the client won't send any.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!