本文整理汇总了C#中IWebSocketConnection类的典型用法代码示例。如果您正苦于以下问题:C# IWebSocketConnection类的具体用法?C# IWebSocketConnection怎么用?C# IWebSocketConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IWebSocketConnection类属于命名空间,在下文中一共展示了IWebSocketConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Client
/// <summary>
/// A fleck client, which provides high-level methods to send data to the client (socket).
/// </summary>
/// <param name="socket">Client socket connection</param>
public Client(IWebSocketConnection socket)
{
State = ClientState.Unknown;
Id = null;
Name = null;
_socket = socket;
}
示例2: Player
public Player(IWebSocketConnection socket, IPrincipal principal)
{
Principal = principal;
_socket = socket;
_socket.OnMessage = message => MessageRecieved(this, message);
_socket.OnClose += LeaveGame;
}
示例3: AddDevice
protected static bool _useSecure = false; //
#endregion Fields
#region Methods
//Add a new device to the list of currently connected devices
private static Device AddDevice(IWebSocketConnection conn, Request requestObject)
{
//Create the device
Device device = new Device()
{
AccountName = requestObject.AccountName,
ConnectionGuid = conn.ConnectionInfo.Id,
FriendlyName = requestObject.FriendlyName,
Id = Guid.Empty,
IP = conn.ConnectionInfo.ClientIpAddress,
Mode = requestObject.CurrentOperationMode
};
//Use the assigned id if the client is supplying one
if (requestObject.DeviceGuid != null)
device.Id = new Guid(requestObject.DeviceGuid); //We have a GUID so update to use that for this connection
//Work out the if we still need a device id and if we do then make one up.
if (device.Id == Guid.Empty) //If the device does not have a guid then request a new one
{
Guid generatedGuid = Guid.NewGuid();
device.Id = generatedGuid;
}//if
//Now actually add the Id to the list
_connectedDevices.TryAdd(device.Id.ToString(), device);
//If we wish to send notifications of on / offline devices then send them now
if (_deviceNotifications)
NotifyDevices(true,device);
//Return the device for use in reading
return device;
}
示例4: handleGame
private void handleGame(IWebSocketConnection socket, String message)
{
Room newRoom = JsonConvert.DeserializeObject<Room>(message);
Room room = Main.ludo.Rooms[newRoom.RoomID];
room.RoomAction = newRoom.RoomAction;
if (room.Game.MoveCount == 0)
{
room.Game.Fields = ludoLogicHandler.initGame(room);
Console.WriteLine(" Init Map: " + room.Game.Fields[0, 0]);
}
if (room.RoomAction.Equals("rollTheDice"))
{
room.Game.DiceValue = rollTheDice();
room.RoomAction = "diceRolled";
Console.WriteLine("Rolled Value: " + room.Game.DiceValue);
room = getUsersTurnID(room);
}
Console.WriteLine("It's " + Main.ludo.Users[room.Game.UsersTurnID].UserName + "'s turn!");
room.Game.MoveCount += 1;
Main.ludo.Rooms[room.RoomID].Game = room.Game;
Console.WriteLine("Field: 0 0" + room.Game.Fields[0, 0]);
Console.WriteLine("Field: 9 0" + room.Game.Fields[9, 0]);
syncGame();
//sendGame(room);
}
示例5: Connection
public void Connection(IWebSocketConnection con, String name)
{
if (isNew) isNew = false;
connections.Add(con, name);
sendToAllNames();
}
示例6: sendOnlineUsers
private void sendOnlineUsers(IWebSocketConnection socket)
{
foreach (var s in onlineUserSocketList.ToList())
{
s.Send(JsonConvert.SerializeObject(Main.ludo));
}
}
示例7: ConfigureIntegrationTestConnectionAndGetId
protected int ConfigureIntegrationTestConnectionAndGetId(IWebSocketConnection connection)
{
var id = Interlocked.Increment(ref _idSeed);
connection.OnOpen = () =>
{
AddConnection(id, connection);
Send(id, $"Open: {id}");
};
connection.OnClose = () =>
{
Send(id, $"Close: {id}");
RemoveConnection(id);
};
connection.OnError = ex =>
{
Send(-1, $"Error: {id} - {ex.ToString()}");
};
connection.OnMessage = m =>
{
Send(id, $"User {id}: {m}");
};
return id;
}
示例8: handleRooms
private void handleRooms(IWebSocketConnection socket, String message)
{
Room room = JsonConvert.DeserializeObject<Room>(message);
Console.WriteLine("JSON: " + message);
if (room.RoomAction.Equals("createRoom"))
{
Console.WriteLine("Room " + room.RoomName + " created");
createRoom(room);
}
if (room.RoomAction.Equals("joinRoom"))
{
joinRoom(room);
}
if (room.RoomAction.Equals("leaveRoom"))
{
leaveRoom(room);
}
if (room.RoomAction.Equals("setReady"))
{
setReady(room);
}
if (room.RoomAction.Equals("setStart"))
{
setStart(room);
}
}
示例9: ServerConfig
public void ServerConfig(IWebSocketConnection socket)
{
socket.OnOpen = () => OnOpen(socket);
socket.OnClose = () => OnClose(socket);
socket.OnMessage = message => OnMessage(socket, message);
socket.OnBinary = bytes => OnBinary(socket, bytes);
}
示例10: NewServiceMap
public WebSocketService NewServiceMap(WebSocketServiceManager _manager, IWebSocketConnection socket)
{
WebSocketService service = null;
switch (_manager.managerName)
{
case "/" + TargetDeiveName.GPS:
service = new GPSService(_manager, socket);
break;
case "/" + TargetDeiveName.UHF:
service = new UHFService(_manager, socket);
break;
case "/" + TargetDeiveName.绿灯:
service = new GreenLightService(_manager, socket);
break;
case "/" + TargetDeiveName.红灯:
service = new RedLightService(_manager, socket);
break;
case "/" + TargetDeiveName.黄灯:
service = new YellowLightService(_manager, socket);
break;
case "/" + TargetDeiveName.电风扇:
service = new FanService(_manager, socket);
break;
case "/" + TargetDeiveName.电机:
service = new EngineService(_manager, socket);
break;
}
return service;
}
示例11: Execute
public override ChatCommand Execute(IWebSocketConnection socket)
{
ChatServer.Instance.ClientConnected(this.ClientName, socket);
ChatCommandConnected res = new ChatCommandConnected();
return res;
}
示例12: NewServiceMap
public WebSocketService NewServiceMap(WebSocketServiceManager _manager, IWebSocketConnection socket)
{
WebSocketService service = null;
switch (_manager.managerName)
{
case "/gps":
service = new GPSService(_manager, socket);
//service.
break;
case "/uhf":
service = new UHFService(_manager, socket);
break;
case "/green_light":
service = new GreenLightService(_manager, socket);
break;
case "/red_light":
service = new RedLightService(_manager, socket);
break;
case "/yellow_light":
service = new YellowLightService(_manager, socket);
break;
case "/fan":
service = new FanService(_manager, socket);
break;
case "/engine":
service = new EngineService(_manager, socket);
break;
}
return service;
}
示例13: closeConnection
public void closeConnection(IWebSocketConnection socket)
{
foreach (var s in allSockets)
{
if (s == socket)
s.Close();
}
}
示例14: OnOpen
public void OnOpen(IWebSocketConnection socket)
{
Logger.Instance().InfoWithFormat(" >> client {0} - {1} connected.", socket.ConnectionInfo.ClientIpAddress, socket.ConnectionInfo.Id);
lock (_lockObj)
{
_clientSocketList.Add(socket);
}
}
示例15: FanService
public FanService(WebSocketServiceManager _manager, IWebSocketConnection socket)
{
services.register_service("fan", this);
this.ID = socket.ConnectionInfo.Id.ToString();
this._manager = _manager;
this._websocket = socket;
this._context = socket.ConnectionInfo;
}