Beispiel #1
0
        public static IFFSocket Connect(string host, SocketMsgHandler funcMsg, SocketBrokenHandler funcBroken)
        {
            string[] strList = host.Split(":");
            if (strList.Length != 3)
            {
                return(null);
            }
            string ip = strList[1];

            string[] ipList = ip.Split("//");
            if (ipList.Length == 2)
            {
                ip = ipList[1];
            }
            else
            {
                ip = ipList[0];
            }

            int        port     = int.Parse(strList[2]);
            SocketCtrl ctrl     = new SocketCtrl(funcMsg, funcBroken);
            IFFSocket  ffsocket = new FFScoketAsync(ctrl);

            if (ffsocket.Connect(ip, port))
            {
                return(ffsocket);
            }
            return(null);
        }
Beispiel #2
0
        public static FFAcceptor Listen(string host, SocketMsgHandler funcMsg, SocketBrokenHandler funcBroken)
        {
            string[] strList = host.Split(":");
            if (strList.Length != 3)
            {
                return(null);
            }
            string ip = strList[1];

            string[] ipList = ip.Split("//");
            if (ipList.Length == 2)
            {
                ip = ipList[1];
            }
            else
            {
                ip = ipList[0];
            }

            int        port       = int.Parse(strList[2]);
            SocketCtrl ctrl       = new SocketCtrl(funcMsg, funcBroken);
            FFAcceptor ffacceptor = new FFAcceptor(ctrl);

            if (ffacceptor.Listen(ip, port))
            {
                return(ffacceptor);
            }
            return(null);
        }
Beispiel #3
0
 public FFAcceptor(SocketRecvHandler onRecv, SocketBrokenHandler onBroken, SocketPreSendCheck f)
 {
     m_oSocket          = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     m_funcRecv         = onRecv;
     m_funcBroken       = onBroken;
     m_funcPreSendCheck = f;
 }
Beispiel #4
0
 public SocketCtrl(SocketMsgHandler funcMsg, SocketBrokenHandler funcBroken)
 {
     size             = 0;
     cmd              = 0;
     flag             = 0;
     m_strRecvData    = "";
     m_funcMsgHandler = funcMsg;
     m_funcBroken     = funcBroken;
 }
Beispiel #5
0
 public SocketCtrl(SocketMsgHandler funcMsg, SocketBrokenHandler funcBroken)
 {
     size             = 0;
     cmd              = 0;
     flag             = 0;
     m_strRecvData    = new byte[0];
     m_funcMsgHandler = funcMsg;
     m_funcBroken     = funcBroken;
     m_oWSProtocol    = new WSProtocol();
 }
Beispiel #6
0
 public FFScoketAsync(SocketRecvHandler onRecv, SocketBrokenHandler onBroken, Socket socket = null)
 {
     if (socket == null)
     {
         m_oSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     }
     else
     {
         m_oSocket = socket;
     }
     m_oBuffer      = new byte[1024];
     m_oBuffSending = "";
     m_oBuffWaiting = "";
     m_funcRecv     = onRecv;
     m_funcBroken   = onBroken;
 }
Beispiel #7
0
        public FFScoketAsync(SocketRecvHandler onRecv, SocketBrokenHandler onBroken, SocketPreSendCheck checkFunc = null, Socket socket = null)
        {
            m_nStatus = 0;
            if (socket == null)
            {
                m_oSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            }
            else
            {
                m_oSocket = socket;
            }

            m_oBuffer          = new byte[1024 * 4];
            m_oBuffSending     = new List <byte[]>();
            m_funcRecv         = onRecv;
            m_funcBroken       = onBroken;
            m_funcPreSendCheck = checkFunc;
            m_sessionData      = null;
            m_strProtocolType  = "";
        }
Beispiel #8
0
        public static FFAcceptor listen(string ip, int port, SocketMsgHandler funcMsg, SocketBrokenHandler funcBroken)
        {
            SocketCtrl ctrl       = new SocketCtrl(funcMsg, funcBroken);
            FFAcceptor ffacceptor = new FFAcceptor(new SocketRecvHandler(ctrl.handleRecv), new SocketBrokenHandler(ctrl.handleBroken));

            if (ffacceptor.listen(ip, port))
            {
                return(ffacceptor);
            }
            return(null);
        }
Beispiel #9
0
        public static FFSocket connect(string ip, int port, SocketMsgHandler funcMsg, SocketBrokenHandler funcBroken)
        {
            SocketCtrl ctrl     = new SocketCtrl(funcMsg, funcBroken);
            FFSocket   ffsocket = new FFScoketAsync(new SocketRecvHandler(ctrl.handleRecv), new SocketBrokenHandler(ctrl.handleBroken));

            if (ffsocket.connect(ip, port))
            {
                return(ffsocket);
            }
            return(null);
        }