Example #1
0
 public Responser(SockController sockController, ProtocolStack protocolStack, SockMgr sockMgr)
 {
     _sockController = sockController;
     if (sockMgr.GetSockBase().Role == SocketRole.Client)  // listener does not need to send or receive
     {
         LinkProtocolStackEvents(protocolStack);
     }
     _sockMgr = sockMgr;
 }
Example #2
0
 public void RemoveSockMgr(SockMgr sockMgr)
 {
     _shutdownLock.WaitOne();
     if (sockMgr.GetSockBase().Role == SocketRole.Listener)
     {
         _sockList.Listeners.Remove(sockMgr);
     }
     else
     {
         _sockList.Clients.Remove(sockMgr);
     }
     _shutdownLock.ReleaseMutex();
 }
Example #3
0
        static void InterfaceMenu(SockMgr sockMgr)
        {
            bool isExit = false;

            while (!isExit && !sockMgr.IsShutdown)
            {
                Console.WriteLine(string.Format("[Interface Menu] {0} -> {1}",
                                                sockMgr.GetSockBase().GetSocket().LocalEndPoint.ToString(),
                                                sockMgr.GetSockBase().GetSocket().RemoteEndPoint.ToString()));
                Console.WriteLine("1. Send Text");
                Console.WriteLine("2. Close");
                Console.WriteLine("3. Is Host?");
                Console.WriteLine("4. Exit");
                Console.WriteLine("5. Config AES");
                Console.WriteLine("6. Send Small File");
                foreach (var proto in sockMgr.GetProtocolStack().GetState().MiddleProtocols)
                {
                    if (proto.GetType() == typeof(Protocol.AESProtocol) && ((Protocol.AESProtocol)proto).GetState().Enabled == false)
                    {
                        Console.WriteLine("[Warning] There exists an AES layer that is not enabled");
                    }
                }

                Console.Write("> ");
                string sel = Console.ReadLine();
                if (sockMgr.IsShutdown)
                {
                    break;
                }
                try
                {
                    switch (sel)
                    {
                    case "1":
                        SendTextConsole(sockMgr);
                        break;

                    case "2":
                        sockMgr.Shutdown();
                        break;

                    case "3":
                        Console.WriteLine(sockMgr.GetSockBase().IsHost.ToString());
                        break;

                    case "4":
                        isExit = true;
                        break;

                    case "5":
                        InterfaceAesConsole(sockMgr);
                        break;

                    case "6":
                        SendSmallFileConsole(sockMgr);
                        break;

                    default:
                        break;
                    }
                }
                catch (NullReferenceException) { }  // in case the remote has shutdown
            }
        }
Example #4
0
 // respond to event at the bottom of the protocol stack
 private void OnNextLowLayerEvent(Protocol.DataContent dataContent)
 {
     _sockMgr.GetSockBase().StartSend((byte[])dataContent.Data, dataContent.ExternalCallback, dataContent.ExternalCallbackState);
 }