/// <summary> /// /// </summary> /// <param name="stackContext"></param> private static void Process_DWR(object sender, object e) { RecievedMessageInfo info = e as RecievedMessageInfo; Message DWR = info.data as Message; Message DWA = new Answer(stackContext).CreateDWA(DWR); SendMessage(DWA, info.PeerIdentity); }
/// <summary> /// This method Process Incoming Messages /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void Process_Message(object sender, object e) { try { RecievedMessageInfo info = e as RecievedMessageInfo; byte[] recievedBuffer = (info.data as byte[]); Message response = new Message(stackContext, recievedBuffer); if (response.CommandCode == 280) { info.data = response; RaisePeerStateChangeEvent(PEER_STATE_EVENT.Rcv_DWR, info); } response.PrintMessage(); } catch (Exception exp) { Common.StackLog.Write2ErrorLog("DiameterAAAStack::Process_Message", "Error:" + exp.Message + " Stack:" + exp.StackTrace); } }
/// <summary> /// /// </summary> /// <param name="listenAddresses"></param> public void StartListners(List <ListenAddress> listenAddresses, ref TcpListener listner) { byte[] responseBuffer = new byte[4000]; try { SocketAddress address = new SocketAddress(System.Net.Sockets.AddressFamily.InterNetwork); foreach (ListenAddress socketAddr in listenAddresses) { Common.StackLog.Write2TraceLog("Transport::SendMessage", "Starting Listening on " + socketAddr.IPAddress.ToString() + " with Port: " + socketAddr.Port.ToString()); listner = new TcpListener(IPAddress.Parse(socketAddr.IPAddress), socketAddr.Port); listner.Start(); Common.StackLog.Write2TraceLog("Transport::SendMessage", "Started Listening on " + listner.LocalEndpoint.ToString()); StackLog.Write2TraceLog("StartListners", "Started Listening on " + socketAddr.IPAddress + ":" + socketAddr.Port.ToString()); } while (true) { //try //{ if (listner.Pending()) { Common.StackLog.Write2TraceLog("Transport::StartListener", "Listening for Peer Connections "); Socket socket = listner.AcceptSocket(); Common.StackLog.Write2TraceLog("Transport::StartListener", "Recieved Message From [" + socket + " ]"); //Get the Message Length Array.Clear(responseBuffer, 0, responseBuffer.Length); int rcvdcount = socket.Receive(responseBuffer); byte[] RcvdBytes = new byte[rcvdcount]; Buffer.BlockCopy(responseBuffer, 0, RcvdBytes, 0, rcvdcount); // IPEndPoint remotePeer = socket.RemoteEndPoint as IPEndPoint; RecievedMessageInfo rcvdObject = new RecievedMessageInfo() { data = RcvdBytes, PeerIdentity = new URI("aaa://" + remotePeer.Address + ":" + remotePeer.Port + ";transport=tcp;protocol=diameter") }; DiameterAAAStack.RaisePeerStateChangeEvent(PEER_STATE_EVENT.Rcv_Message, RcvdBytes); Array.Clear(responseBuffer, 0, responseBuffer.Length); } //} //catch (Exception ex) //{ //} } } catch (Exception exp) { //Write Log Here.. Common.StackLog.Write2ErrorLog("Transport::StartListners()", "Error:" + exp.Message + " Stack:" + exp.StackTrace); //Shutdown and end connection //listner.Stop(); //throw exp; } finally { listner.Stop(); } }