internal void TerminateApp() { var srpc = new Srpc.Message(); srpc.Set(Srpc.Key.Method, "MainLoop_EndLoop"); Send(srpc); }
private void HandleRequest(Srpc.Message request) { if (_fOnMessage != null) { var response = new Srpc.Message(); _fOnMessage(ref request, ref response); } }
void OnConnectedMainThread() { _form.SetConnected(_bConnected); var srpc = new Srpc.Message(); srpc.Set(Srpc.Key.Method, Protocol.Hello.Method); Send(srpc); }
void Send(Srpc.Message srpc, Client.SrpcCompletion fComplete) { if (_bConnected) { if (_client != null) { _client.Send(srpc, fComplete); } } }
internal void Send(Srpc.Message msg, SrpcCompletion fComplete) { if (fComplete != null) { string sSrpcId = "_" + _nSrpcId++; msg.Set("SrpcId", sSrpcId); _completions.Add(sSrpcId, fComplete); } Send(msg.ToString() + "\n"); }
void OnReceived(IAsyncResult iar) { //Socket remoteSocket = (Socket)iar.AsyncState; // disposed lock (this) { if (_socket == null) { OnDisconnected(); } else { _bReceiving = false; int nBytesRead = 0; try { nBytesRead = _socket.EndReceive(iar); } catch { } if (nBytesRead == 0) { OnDisconnected(); } else { string sData = Encoding.UTF8.GetString(_bytes, 0, nBytesRead); Log("IN " + sData); _sBuffer += sData; Srpc.Message srpc = null; do { srpc = ProcessData(ref _sBuffer); if (srpc != null) { string sStatus = srpc.GetString(Srpc.Key.Status); if (!String.IsNullOrEmpty(sStatus)) { HandleResponse(srpc); } else { HandleRequest(srpc); } } } while (srpc != null); Receive(); } } } }
private Srpc.Message ProcessData(ref string sData) { Srpc.Message msg = null; string sLfClean = sData.Replace("\r\n", "\n"); int nEnd = sLfClean.IndexOf("\n\n"); if (nEnd >= 0) { string sMessage = sLfClean.Substring(0, nEnd + 1); sData = sLfClean.Substring(nEnd + 2); msg = new Srpc.Message(sMessage); } return(msg); }
private void HandleResponse(Srpc.Message response) { string sSrpcId = response.GetString(Srpc.Key.SrpcId); if (!String.IsNullOrEmpty(sSrpcId)) { if (_completions.ContainsKey(sSrpcId)) { var fCompletion = _completions[sSrpcId]; if (fCompletion != null) { fCompletion(response); } _completions.Remove(sSrpcId); } } }
void OnMessage(ref Srpc.Message request, ref Srpc.Message response) { string sMethod = request.GetString(Srpc.Key.Method); switch (sMethod) { case Protocol.Status.Method: { int nConnections = request.GetInt(Protocol.Status.Key.Connections); if (nConnections > 0) { Invoke(() => _form.ShowConnectedAppStatus()); } else { Invoke(() => _form.ShowDisconnectedAppStatus()); } } break; } }
public SrpcException(Srpc.Message msg) { _srpcMessage = msg; }
internal void Send(Srpc.Message msg) { Send(msg, null); }
void Send(Srpc.Message srpc) { Send(srpc, null); }