Pass client id/information from a .NET client to a web socket service
Is there a way to pass client information (such as an Id, username or other contextual information) from the client as part of making a websocket connection from a .net client(console,silverlight etc)? This is how I'm making the connection to the socket service.
using (WebSocket socket = new WebSocket(@"ws://"+Environment.MachineName+":4502/commandserver"))开发者_StackOverflow
{
socket.OnClose += socket_OnClose;
socket.OnData += socket_OnData;
socket.OnOpen += socket_OnOpen;
socket.Open();
}
The ctor has an overload that accepts an "origin" and a "protocol", not sure if this can be used for passing any client information. If not is there an API call I can make to pass in the client information as part of making the connection?
EDIT: I'm using the microsoft library for this and the sample service code adds the service object into a collection in it's ctor to keep track of client sessions. Hence I need a way to pass in some client data to the service object as part of the initial client connection so that I can use this to identify clients and send messages to specific clients (based on an ID for example) from the service.
精彩评论