public static void QueueCommand(string cmds, SocketCommunicator sc) { //Initialize RobotCommandList List <RobotCommand> robotCommandList = new List <RobotCommand>(); string[] cmdList = cmds.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); foreach (string cmd in cmdList) { robotCommandList.Add(new RobotCommand(cmd)); } //Use RobotCommandList to update current robot commands foreach (RobotCommand cmd in robotCommandList) { if (cmd.id == 1) //double checking is probably not necessary { foreach (RobotCommand _cmd in commandQueue) { cachedRobotCommands[_cmd[0]] = _cmd; } updatedFromCache = false; currentRobotCommands = new Dictionary <string, RobotCommand>(cachedRobotCommands); updatedFromCache = true; commandQueue.Clear(); return; } commandQueue.Add(cmd); } }
public byte Read(ObjectLocation objLocation) { SocketCommunicator.Send(_socket, new ReadMessage { ObjectLocation = objLocation }); return(GetReadResponse().Value); }
void StartClient() { string msg; msg = sc.GetMessage(); if (msg == "RESET") { while (true) { msg = sc.GetMessage(); if (!connected) { sc.SendMessage("RESET"); CommandHandler.ClearCommands(); break; } if (msg == "RESET") { break; } CommandHandler.QueueCommand(msg, sc); } } else { sc.SendMessage("RESET"); } connected = false; sc.CloseClient(); sc = null; }
public void HandleEndStagingPhaseMessage(EndStagingPhaseMessage endStagingPhaseMessage, Socket socket) { Vote vote = _dataManager.EndStagingPhase(); SocketCommunicator.Send(socket, new EndStagingPhaseResponse { Vote = vote }); }
public void HandleReadMessage(ReadMessage readMessage, Socket socket) { byte readValue = _dataManager.Read(readMessage.ObjectLocation); SocketCommunicator.Send(socket, new ReadResponse { Value = readValue }); }
void helper_MessageReceivedEvent(SocketCommunicator helper, object message) { MessageUpdateDelegate del = ClientMessageReceivedEvent; if (del != null) { del(this, (SocketCommunicatorEx)helper, message); } }
void helper_SendAsyncCompleteEvent(SocketCommunicator helper, SocketCommunicator.AsyncMessageSendInfo info) { AsyncMessageSendUpdateDelegate del = ClientAsyncMessageSendEvent; if (del != null) { del(this, helper as SocketCommunicatorEx, info); } }
void _messageClient_ConnectedEvent(SocketCommunicator helper) { // Send an update of the clients to server. if (_socketClient == helper) { SendAccessControlMessage(); SendClientsUpdate(); } }
void _messageClient_SendAsyncCompleteEvent(SocketCommunicator helper, SocketCommunicator.AsyncMessageSendInfo info) { // Message sent to server. MessageUpdateDelegate del = MessageUpdateEvent; if (del != null) { del(this, info.Message); } }
void helper_DisconnectedEvent(SocketCommunicator client) { //Monitor.ReportImportant("Client [" + client.Id + "] disconnected."); ServerClientUpdateDelegate delegateInstance = ClientDisconnectedEvent; if (delegateInstance != null) { delegateInstance(this, client as SocketCommunicatorEx); } }
private void HandleConnection(object receivingSocketObj) { Socket receivingSocket = (Socket)receivingSocketObj; while (receivingSocket.Connected) { BaseMessage message = SocketCommunicator.Receive(receivingSocket); CommandMessage commandMessage = (CommandMessage)message; commandMessage.HandleCommandMessage(this, receivingSocket); } Console.WriteLine("Conn closed"); }
void _messageClient_DisconnectedEvent(SocketCommunicator helper) { ICollection <ClientId> ids = _originalServerClientsHotSwap.Values; _originalServerClientsHotSwap.Clear(); //lock (_syncRoot) //{ // _localToRemoteId.Clear(); //} // Removing all server clients. foreach (ClientId id in ids) { // Notify of clients removal, with non permanent remove, since they may later be restored. RaiseClientRemovedEvent(id, false); } }
void StartSimulation() { connected = true; try { sc = new SocketCommunicator(29071); sc.thread = new Thread(new ThreadStart(StartClient)); sc.thread.Start(); } catch (SocketException e) { Debug.LogError("There was an error connecting to the controller."); } catch (Exception e) { Debug.Log(e.ToString()); } }
void _messageClient_MessageReceivedEvent(SocketCommunicator helper, object message) { if (message is EnvelopeMessage) { EnvelopeMessage envelopeMessage = (EnvelopeMessage)message; // Remove the remote message bus index association. envelopeMessage.Sender.LocalMessageBusIndex = ClientId.InvalidMessageBusClientIndex; foreach (ClientId id in envelopeMessage.Receivers) { // Decode the id. id.LocalMessageBusIndex = base.GetClientIndexByGuid(id.Guid); if (id.IsMessageBusIndexValid) { // Assign as a part of the local bus. id.MessageBus = this; if (DoSendToClient(envelopeMessage.Sender, id, envelopeMessage.Envelope, null) != SendToClientResultEnum.Success) { #if Matrix_Diagnostics InstanceMonitor.OperationError(string.Format("Failed to accept envelope message [{0}].", envelopeMessage.ToString())); #endif } } else { #if Matrix_Diagnostics InstanceMonitor.OperationError(string.Format("Failed to accept envelope message [{0}] due to unrecognized receiver id.", envelopeMessage.ToString())); #endif } } } else if (message is ClientsListMessage) {// Received client update from server. ClientsListMessage listMessage = (ClientsListMessage)message; int jef = 0; foreach (var client in listMessage.Ids) { Console.WriteLine("Incoming client id: " + client + " Source type: " + listMessage.SourcesTypes[jef]); jef++; } List <ClientId> existingIds = new List <ClientId>(); lock (_syncRoot) { existingIds.AddRange(_originalServerClientsHotSwap.Values); _originalServerClientsHotSwap.Clear(); _originalServerClientsTypesHotSwap.Clear(); _originalServerClientsSourcesTypesHotNamesSwap.Clear(); // Preprocess Ids, by assigning them new indeces and adding to the local message bus register. for (int i = 0; i < listMessage.Ids.Count; i++) { // Add an original copy to the list. _originalServerClientsHotSwap.Add(listMessage.Ids[i].Guid, listMessage.Ids[i]); _originalServerClientsTypesHotSwap.Add(listMessage.Ids[i].Guid, listMessage.Types[i]); _originalServerClientsSourcesTypesHotNamesSwap.Add(listMessage.Ids[i].Guid, listMessage.SourcesTypes[i]); // Add the client to a new spot. //_clientsHotSwap.Add(null); //int messageBusIndex = _clientsHotSwap.Count - 1; // This type of assignment will also work with multiple entries. // This performs an internal hotswap. //_guidToIndexHotSwap[id.Guid] = messageBusIndex; // Also add to this classes collection. //_localToRemoteId[messageBusIndex] = id; } } foreach (ClientId id in listMessage.Ids) { existingIds.Remove(id); RaiseClientAddedEvent(id); } // Raise for any that were removed. foreach (ClientId id in existingIds) { RaiseClientRemovedEvent(id, true); } } else if (message is RequestClientListUpdateMessage) { SendClientsUpdate(); } else if (message is ClientUpdateMessage) { ClientUpdateMessage updateMessage = (ClientUpdateMessage)message; if (_originalServerClientsHotSwap.ContainsKey(updateMessage.ClientId.Guid)) { RaiseClientUpdateEvent(updateMessage.ClientId); } else { #if Matrix_Diagnostics InstanceMonitor.OperationError(string.Format("Failed to raise update event for client [{0}], since client not found.", updateMessage.ClientId.ToString())); #endif } } else if (message is StateUpdateMessage) { RaiseCounterPartyUpdateEvent("Server", ((StateUpdateMessage)message).State.ToString()); } else { #if Matrix_Diagnostics InstanceMonitor.Warning(string.Format("Message [{0}] not recognized.", message.GetType().Name)); #endif } }
private ReadResponse GetReadResponse() { object message = SocketCommunicator.Receive(_socket); return((ReadResponse)message); }
public void Begin() { SocketCommunicator.Send(_socket, new BeginMessage()); }
public void End() { SocketCommunicator.Send(_socket, new EndMessage()); }
void helper_ConnectedEvent(SocketCommunicator helper) { // This is never invoked, since we create the helpers directly on the connected sockets. }
public void Abort() { SocketCommunicator.Send(_socket, new AbortMessage()); }
public void Restart() { SocketCommunicator.Send(_socket, new RestartMessage()); }
public void Setup() { ConfigurationMock = new Mock <IConfiguration>(); CommandSerializer = new CommandSerializer(); SocketCommunicator = new SocketCommunicator <Command>(ConfigurationMock.Object, CommandSerializer); }
private EndStagingPhaseResponse GetEndStagingPhaseResponse() { object message = SocketCommunicator.Receive(_socket); return((EndStagingPhaseResponse)message); }
public Vote EndStagingPhase() { SocketCommunicator.Send(_socket, new EndStagingPhaseMessage()); return(GetEndStagingPhaseResponse().Vote); }
public void StageChange(Change change) { SocketCommunicator.Send(_socket, new StageChangeMessage { Change = change }); }
/// <summary> /// Initializes a new instance of the <see cref="MazeServer"/> class. /// </summary> /// <param name="ip">The ip of the server.</param> /// <param name="port">The port of the server.</param> public MazeServer(string ip, int port) { this.server = new SocketCommunicator(ip, port); }
// Start is called before the first frame update void Start() { socket = new SocketCommunicator("127.0.0.1", 56789, 1024); dataList = new float[3]; StartCoroutine(Communicate()); }