c# - The server returned status code '200' when status code '101' was expected in WebSockets -
i'm new web sockets, have written 1 sample c# console application web socket client , server. when connecting server client, receive above exception if specify httplistenerprefix url ip address either client or server (but not both). if specify machine name instead, worked expected.
server code:
//server.start("http://inpsservice10:80/"); server.start("http://131.163.140.92:80/"); } public async void start(string httplistenerprefix) { httplistener httplistner = new httplistener(); httplistner.prefixes.add(httplistenerprefix); httplistner.start(); console.writeline("listening"); while(true) { httplistenercontext httplistencontext = await httplistner.getcontextasync(); if (httplistencontext.request.iswebsocketrequest) processrequest(httplistencontext); else { httplistencontext.response.statuscode = 400; httplistencontext.response.close(); } } }
client code:
connect("ws://131.163.140.92:80/").wait(); private static async task connect(string uri) { thread.sleep(1000); clientwebsocket websocket = null; try { websocket = new clientwebsocket(); await websocket.connectasync(new uri(uri), cancellationtoken.none); //i'm getting exception here. await task.whenall(receive(websocket), send(websocket)); } catch (exception ex) { console.writeline("conenct: " + ex.message); } }
can i know which library are you using?
ReplyDelete