Exemplo n.º 1
0
            /// <summary>
            /// 登陆行情服务器
            /// </summary>
            /// <param name="_username">用户名称</param>
            /// <param name="_password">密码</param>
            /// <param name="_callbackIP">回掉的IP地址</param>
            /// <returns></returns>
            public bool Login(string _username, string _password, string _callbackIP)
            {
                UserName   = _username;
                Password   = _password;
                CallbackIP = _callbackIP;

                PDUHead pdh = new PDUHead();

                pdh.setCommandId(PDUHead.JH_LOGIN);
                pdh.setStatus(0);
                pdh.setSvrTime(0);
                pdh.setTotalLength(PDUHead.PDU_HEAD_LEN + PDUHead.JH_LOGIN_LEN);

                byte[] head  = pdh.ToByteArray();
                byte[] body  = pdh.LoginBody(_username, _password, _callbackIP);
                byte[] login = pdh.HeadAndBody(head, body);

                try
                {
                    sock.Send(login);
                    byte[] rspl = new byte[14];
                    int    len  = sock.Receive(rspl, PDUHead.PDU_HEAD_LEN, SocketFlags.None);
                    if (len != PDUHead.PDU_HEAD_LEN)
                    {
                        JHLog.forMarketLog("登陆行情服务器失败!");
                        return(false);
                    }
                    PDUHead pDU = new PDUHead();
                    pDU.fromString(rspl);
                    if (pDU.status != 0)
                    {
                        JHLog.forMarketLog("登陆行情服务器失败!");
                        return(false);
                    }

                    //登陆成功后消息推送给客户端
                    jhMarket.OnLogin(pDU.svrTime + "");
                    //启动行情接收线程
                    thread = new Thread(new ParameterizedThreadStart(ReceiveThread));
                    thread.Start(this);
                    return(true);
                }catch (Exception ex)
                {
                    JHLog.forMarketLog("登陆行情服务器失败!" + ex.Message);
                    return(false);
                }
            }
Exemplo n.º 2
0
            public static Int32 WM_FQ_COMM_MSG   = (0x0400 + 100 + 300 + 1); //socket通讯端口消息进入
                                                                             //将字节数组转换成 PDUHead
            public static PDUHead byteToPDUHead(byte[] head)
            {
                if (head == null)
                {
                    return(null);
                }

                PDUHead ph = new PDUHead();
                int     i = 0, j = 0;

                byte[] total = new byte[4];
                total[i++] = head[j++];
                total[i++] = head[j++];
                total[i++] = head[j++];
                total[i++] = head[j++];
                Array.Reverse(total);

                i = 0;
                byte[] comm = new byte[4];
                comm[i++] = head[j++];
                comm[i++] = head[j++];
                comm[i++] = head[j++];
                comm[i++] = head[j++];
                Array.Reverse(comm);

                i = 0;
                byte[] svrt = new byte[4];
                svrt[i++] = head[j++];
                svrt[i++] = head[j++];
                svrt[i++] = head[j++];
                svrt[i++] = head[j++];
                Array.Reverse(svrt);

                i = 0;
                byte[] status = new byte[2];
                status[i++] = head[j++];
                status[i++] = head[j++];
                Array.Reverse(status);

                ph.setTotalLength(BitConverter.ToInt32(total, 0));
                ph.setCommandId(BitConverter.ToInt32(comm, 0));
                ph.setSvrTime(BitConverter.ToInt32(svrt, 0));
                ph.setStatus(BitConverter.ToInt16(status, 0));

                return(ph);
            }