private void SetStatus(State myState) { m_State = myState; // construct an kai message wrapper KaiMessageWrap myWrap = new KaiMessageWrap(); string myTemp = ""; switch (m_State) { case State.closed: myTemp = GatewayStatus.CLOSED; break; case State.closing: myTemp = GatewayStatus.CLOSING; break; case State.open: myTemp = GatewayStatus.OPEN; break; case State.opening: myTemp = GatewayStatus.OPENING; break; default: myTemp = GatewayStatus.NONE; break; } myWrap.Data = m_EndPoint; myWrap.Label = myTemp; myWrap.CorrelationID = ""; myWrap.Tag = m_Tag; if (m_Status != null) { m_Status(myWrap); } }
private void EventGatewayClients(ref string myContent, string myLabel, ref Socket myHandler) { try { // get my end point m_EndPoint = myHandler.RemoteEndPoint.ToString(); // construct an kai message wrapper KaiMessageWrap myWrap = new KaiMessageWrap(); myWrap.Data = myContent; myWrap.Label = myLabel; // Use the Corrlation ID to store the endpoint // all return messages with that correlationID will // be sent down the relevant socket myWrap.CorrelationID = m_EndPoint; myWrap.Tag = m_Tag; // event our gateway clients m_Receiver(myWrap); } catch { ////m_Log.Error("EventGatewayClients", myE); } }
private void send(ref KaiMessageWrap myMsg, Socket myClient) { string myData; StreamHelper.WriteMsg(out myData, myMsg); send(m_Client, myData); }
public void Send(KaiMessageWrap myMsg) { send(ref myMsg, null); }
public static void WriteMsg(out string myData, KaiMessageWrap myKaiMsg) { myData = strTok; myData += myKaiMsg.Label; myData += strDelim; myData += myKaiMsg.ClientID; myData += strDelim; myData += myKaiMsg.Data.Length.ToString(); myData += strEndTok; myData += myKaiMsg.Data; }
/// <summary> /// Inform the client of a status change, if a correlationID(EndPoint) is /// specified that status relates to a particular connection. /// </summary> /// <param name="myState"></param> /// <param name="myCorrelationID">socket connecton affected , empty string => all</param> private void SetStatus(State myState, string myCorrelationID) { m_State = myState; // construct a kai message wrapper KaiMessageWrap myWrap = new KaiMessageWrap(); myWrap.Data = myCorrelationID; myWrap.CorrelationID = myCorrelationID; switch (m_State) { case State.closed: myWrap.Label = "CLOSED"; break; case State.closing: myWrap.Label = "CLOSING"; break; case State.open: myWrap.Label = "OPEN"; break; case State.opening: myWrap.Label = "OPENING"; break; default: myWrap.Label = "NOTKNOWN"; break; } if (m_Status != null) { m_Status(myWrap); } }
private void EventGatewayClients(ref string myContent, string myLabel, ref Socket myHandler) { try { // get my end point string myRemoteEP = myHandler.RemoteEndPoint.ToString(); // construct an kai msg wrapper KaiMessageWrap myWrap = new KaiMessageWrap(); myWrap.Data = myContent; myWrap.Label = myLabel; // Use the Corrlation ID to store the endpoint // all return messages with that correlationID will // be sent down the relevant socket myWrap.CorrelationID = myRemoteEP; // event our gateway clients m_Receiver(myWrap); } catch (Exception myE) { //m_Log.Error("EventGatewayClients", myE); setStatus(State.open, ErrorLevel.recoverableError); } }
public void Send(ref KaiMessageWrap myMsg) { try { // try to get the socket from the map - using the correlationID if (myMsg.CorrelationID.Length > 0) { if (m_Handlers.ContainsKey(myMsg.CorrelationID)) { Socket myHandler = m_Handlers[myMsg.CorrelationID] as Socket; // add our message headers string myData; StreamHelper.WriteMsg(out myData, myMsg); Send(myHandler, myData); } else { Exception myE = new Exception("Handler not found for:" + myMsg.CorrelationID); setStatus(State.open, ErrorLevel.recoverableError); throw (myE); } } else { Exception myE = new Exception("No correlation ID - can't send message"); throw (myE); } } catch (Exception myE) { if (m_Handlers.ContainsKey(myMsg.CorrelationID)) { //m_Log.Warn("Send - correlation ID removed from handler list due to fault:" + myMsg.CorrelationID); m_Handlers.Remove(myMsg.CorrelationID); } try { setStatus(State.closed, ErrorLevel.normal, myMsg.CorrelationID); } catch { } throw (myE); } }