Exemplo n.º 1
0
            internal static void Dispatch(NonBlockingConnection conn, ActionBean bean, Protocol protocol)
            {
                int  priority = 1;
                Task task     = new Task(priority, bean, conn, protocol);

                ThreadPool.AddTask(task);
            }
Exemplo n.º 2
0
 public void _userLogin_1001(UserLoginParams param, NonBlockingConnection conn)
 {
     //TODO Your Code Here
     ConsoleEx.DebugLog(string.Format("The UserName is {0}", param.userName));
     ConsoleEx.DebugLog(string.Format("The Password is {0}", param.passwd));
     ConsoleEx.DebugLog(string.Format("The Firends size is {0}", param.firends.Count));
 }
Exemplo n.º 3
0
 public bool OnConnect(NonBlockingConnection conn)
 {
     ConsoleEx.DebugLog("Connect to the Server.");
     curConnectType = isConnectType.isConnected;
     HandleTask();
     return(true);
 }
Exemplo n.º 4
0
            private Task(int priority, ActionBean bean, NonBlockingConnection conn, Protocol protocol) : base(priority)
            {
                this.bean     = bean;
                this.conn     = conn;
                this.protocol = protocol;

                time_start = WatchDog.GetTime();
            }
Exemplo n.º 5
0
        public void DispatchAct(Protocol protocol, NonBlockingConnection conn)
        {
            ActionBean bean = null;

            if (actions.TryGetValue(protocol.act, out bean))
            {
                // 分配一个线程执行
                Task.Dispatch(conn, bean, protocol);
            }
        }
Exemplo n.º 6
0
    public void OnLogin(object ServerEndPoint)
    {
        endPoint = ServerEndPoint as DnsEndPoint;
        Conn     = new NonBlockingConnection(endPoint.Host, endPoint.Port, this);

        if (curConnectType == isConnectType.isConnecting)
        {
            curConnectType = isConnectType.isDisconnect;
        }
    }
Exemplo n.º 7
0
    public void sendTcpRequest()
    {
        DataHandler           handler = new DataHandler();
        NonBlockingConnection conn    = new NonBlockingConnection("192.168.1.55", 8001, handler);

        System.Threading.Thread.Sleep(1000);

        for (int i = 0; i < 10; i++)
        {
            conn.Write("madongfang\r\n");
        }
    }
Exemplo n.º 8
0
        // 接收数据
        public bool OnData(NonBlockingConnection conn)
        {
            ConsoleEx.DebugLog("Receive data from the server !!");
            IList <string> json = conn.ReadStrings();

            ConsoleEx.DebugLog("The list size is " + json.Count);
            foreach (string s in json)
            {
                ConsoleEx.DebugLog(s + "==========");
            }
            return(true);
        }
Exemplo n.º 9
0
    public bool OnData(NonBlockingConnection conn)
    {
        IList <string> json = conn.ReadStrings();

        if ((json == null) || (json.Count == 0))
        {
            return(true);
        }

        foreach (string s in json)
        {
            ActProtocol p = JSON.Instance.ToObject <ActProtocol>(s);
            Dispatch.Instance.DispatchAct(p, conn);
        }
        return(true);
    }
Exemplo n.º 10
0
            public void invoke(Protocol proto, NonBlockingConnection conn)
            {
                if (proto.act != this.actId)
                {
                    return;
                }
                if (proto.data == null)
                {
                    return;
                }

                ConsoleEx.DebugLog("Receive Protocol :: " + proto.ToString());

                IFuncParam newParam = getParamObje(proto.data);

                try{
                    mi.Invoke(action, new Object[] { newParam, conn });
                } catch (Exception e) {
                    ConsoleEx.DebugLog(e.ToString());
                }
            }
Exemplo n.º 11
0
    public bool OnData(NonBlockingConnection conn)
    {
        IList <string> json = conn.ReadStrings();

        if ((json == null) || (json.Count == 0))
        {
            return(true);
        }

        foreach (string s in json)
        {
            string     acknowledge = s.Trim();
            int        Act         = getAct(acknowledge);
            SocketTask task        = null;
            if (TaskQueue.TryGetValue(Act, out task))
            {
                if (task.respType == TaskResponse.Default_Response || task.respType == TaskResponse.Donot_Send)
                {
                    if (Utils.checkJsonFormat(acknowledge))
                    {
                        SocketResponseFactory.createResponse(task, acknowledge);
                        Socket_OnReceive(task);
                    }
                    else
                    {
                        ExceptionResponse exResp = new ExceptionResponse();
                        exResp.HttpError = acknowledge;
                        task.response    = exResp;
                        Socket_OnException(task);
                    }
                }
            }
            else
            {
                Socket_CommException(acknowledge);
            }
        }

        return(true);
    }
Exemplo n.º 12
0
 public bool OnException(NonBlockingConnection conn, Exception e)
 {
     Socket_CommException(e.ToString());
     curConnectType = isConnectType.isDisconnect;
     return(true);
 }
Exemplo n.º 13
0
 public bool OnDisconnect(NonBlockingConnection conn)
 {
     Socket_CommException("Disconnect from the Server.");
     curConnectType = isConnectType.isDisconnect;
     return(true);
 }
Exemplo n.º 14
0
 public bool OnConnect(NonBlockingConnection conn)
 {
     ConsoleEx.DebugLog("Collect to the Server    java  ");
     return(true);
 }
Exemplo n.º 15
0
 // 断开连接
 public bool OnDisconnect(NonBlockingConnection conn)
 {
     ConsoleEx.DebugLog("DisConnect from the server !!");
     return(true);
 }
Exemplo n.º 16
0
 // 发生异常
 public bool OnException(NonBlockingConnection conn, Exception e)
 {
     ConsoleEx.DebugLog("Exception occur, the exception is " + e.ToString());
     return(true);
 }
Exemplo n.º 17
0
 private Task(int priority, ActionBean bean, NonBlockingConnection conn, Protocol protocol) : base(priority)
 {
     this.bean     = bean;
     this.conn     = conn;
     this.protocol = protocol;
 }
Exemplo n.º 18
0
 // 创建连接
 public bool OnConnect
     (NonBlockingConnection conn)
 {
     ConsoleEx.DebugLog("Connect to the server  in  test!");
     return(false);
 }
Exemplo n.º 19
0
 public bool OnException(NonBlockingConnection conn, Exception e)
 {
     ConsoleEx.DebugLog("Exception happen exception :: " + e.ToString());
     return(true);
 }