public static T FromBytes <T>(IServerRequest <T> response, byte[] responseBytes) { using (MemoryStream ms = new MemoryStream(responseBytes)) { return(response.GetRequest(ms)); } }
public void ResponseFromServer(IServerRequest serverRequest) { var response = _activeRequests[serverRequest.RequestId]; _activeRequests.Remove(serverRequest.RequestId); response(serverRequest); }
private static void HandleServerRequest(string value) { value = value.Trim(); string instruction = value; string args = null; // Check if we got parameters with the instruction if (value.IndexOf(' ') > -1) { instruction = value.SplitCommand()[0]; args = value.SplitCommand()[1]; } // Is request registered? IServerRequest request = ServerRequestRegistry.GetHandler(instruction); if (request != null) { request.Run(args); } else { // Protocol request unknown, inform client ClientMessage.Info($"Unknown protocol value: {value}"); } }
private void HandleCommand(User user, string value) { // Default return message string response = "ERROR Unknown command"; value = value.Trim(); string instruction = value; string args = null; // Check if we got parameters with the instruction if (value.IndexOf(' ') > -1) { instruction = value.SplitCommand()[0]; args = value.SplitCommand()[1]; } IServerRequest request = CommandRegistry.GetCommand(instruction); if (request != null) { request.Run(user, args); } else { // Unknown command, inform client user.WriteLine(response); } }
public void MakeRequest(IServerRequest request, Action<IServerRequest> response) { request.RequestId = _requestId++; _activeRequests.Add(request.RequestId, response); SendServerRequest(request); }
public void MakeRequest(IServerRequest request, Action <IServerRequest> response) { request.RequestId = _requestId++; _activeRequests.Add(request.RequestId, response); SendServerRequest(request); }
protected void SendServerRequest(IServerRequest serverRequest) { var myEvent = SendRequestToServer; if (myEvent == null) throw new Exception("There is no subscribtion of Server Request Engine"); myEvent(this, new EventArgs<IServerRequest>(serverRequest)); }
private byte[] GetResponseBytes(IServerRequest request) { var udpClient = new UdpClient(_server.Address.ToString(), _server.Port); udpClient.Send(request); var remoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0); var bytesReceived = udpClient.Receive(ref remoteIpEndPoint); return bytesReceived; }
protected void SendServerRequest(IServerRequest serverRequest) { var myEvent = SendRequestToServer; if (myEvent == null) { throw new Exception("There is no subscribtion of Server Request Engine"); } myEvent(this, new EventArgs <IServerRequest>(serverRequest)); }
private async Task <string> SendRequest(IServerRequest requestPayload) { try { HttpResponseMessage response = await webClient.PostAsync( requestPayload.getEndpoint(), new StringContent(requestPayload.getPayload(), Encoding.UTF8, "application/json")); Console.WriteLine(response.Content.ReadAsStringAsync().Result); return(await response.Content.ReadAsStringAsync()); } catch (TimeoutException e) { Console.WriteLine(e.StackTrace); return(null); } }
public static void RegisterCommand(string command, IServerRequest handler) { command = command.ToUpper(); Commands.Add(command, handler); }
public void ResponseFromServer(IServerRequest serverRequest) { var response = _activeRequests[serverRequest.RequestId]; _activeRequests.Remove(serverRequest.RequestId); response(serverRequest); }
public static int Send(this UdpClient udpClient, IServerRequest request) { var bytes = request.ToBytes(); return udpClient.Send(bytes, bytes.Length); }