c# - ASP.net SignalR server without knowing the client -
we trying setup websockets server using signalr connect our devices. project hosted in web app published on azure.
but have 3 issues : - devices going send device name @ end of url. if url ws://url:port/myservice, devices send message ws://url:port/myservice/devicename
and device name different each device. should configuration of routes hub ?
we'd save name in clients list of signalr able call ones.
- we don't know name of function called, requests clients send json object parameter. how can configure hub redirect requests newmessage(string json) ?
we've managed messages devices using :
websocket socket = context.websocket; while (true) { var url = context.requesturi; arraysegment<byte> buffer = new arraysegment<byte>(new byte[1024]); websocketreceiveresult result = await socket.receiveasync(buffer, cancellationtoken.none); if (socket.state == websocketstate.open) { string usermessage = encoding.utf8.getstring(buffer.array, 0, result.count) .trim(new char[] { ' ' }); // remove spaces before , after } else { break; } }
but thought code complicated , not send messages devices. ==> correct me if i'm wrong code connection closed every time , can't send messages device connected.
for example need create api "sendsomethingtothedevice" called random client , have send message device , have opened connection device.
- related second problem, need able send messages devices without knowing function call, need send json object parameter. name should use our function clients.all."function_name"(myjson)?
i hope i've described problem enough. thank help
Comments
Post a Comment