예제 #1
0
 private static void OnEventHappen(SocketInfoType type, int value)
 {
     if (ClientSystemInfo.ValueChangeEvent != null)
     {
         ClientSystemInfo.ValueChangeEvent(null, new SocketEventArgs(type, value));
     }
 }
예제 #2
0
    public static SERVICE_CODE ConnectToService(SocketInfoType socketInfoType)
    {
        SERVICE_CODE  service_code=SERVICE_CODE.SUCCESS;
        int socketType = (int)socketInfoType;
        if (!connectorMap.ContainsKey(socketType))
        {
            //CommonTrace.Log("ConnectToService");
            if (AddrConfMap.ContainsKey(socketType))
            {
                //CommonTrace.Log("AddrConfMap.ContainsKey(socketType)");
                IpInfo info = AddrConfMap[socketType];
                switch (info.baseType)
                {
                    case BASESOCKET_TYPE.SOCKET_TCP:
                        TcpSocket tcpSocket = new TcpSocket();
                        try
                        {
                            SOCKET_CODE socketCode= tcpSocket.SocketConnect(info.ip, info.port);
                            if (socketCode == SOCKET_CODE.SUCCESS)
                            {
                                connectorMap[socketType] = tcpSocket;
                            }
                            else
                            {
                                service_code = SERVICE_CODE.ERROR_CONNECT;
                            }
                        }
                        catch (System.Exception)
                        {
                            service_code= SERVICE_CODE.ERROR_CONNECT;
                        }
                        break;

                    case BASESOCKET_TYPE.SOCKET_UDP:
                        UdpSocket udpSocket = new UdpSocket();
                        udpSocket.SetRemote(info.ip, info.port);
                        connectorMap[socketType] = udpSocket;
                       
                        break;

                    default:
                        break;
                }
            }
            else
            {
                //CommonTrace.Log("!AddrConfMap.ContainsKey(socketType)");
                service_code = SERVICE_CODE.ERROR_NOCONF;
            }
        }
        return service_code;
    }
예제 #3
0
파일: FormMain.cs 프로젝트: ckbcjj/jxcar
        private void LM_ListenEvent(object sender, ListenEventArgs e)
        {
            SocketInfoType eventType = e._eventType;

            if (eventType != SocketInfoType.CheckItem)
            {
                if (eventType != SocketInfoType.RealTimeData)
                {
                    return;
                }
                RTData data = e.value as RTData;
                base.Invoke(new MethodInvoker(delegate
                {
                    this.labelControl1.Text = string.Format("发动机冷却液温度:{0}", data.FDJLQYWD);
                    this.labelControl2.Text = string.Format("发动机转速:{0}", data.FDJZS);
                }));
            }
            else
            {
                CheckInfo.PcCheckState = true;
                this.time = DateTime.Now;
                if (MessageBox.Show("教师已发考题。\n 立即答题点击是;\n 稍后答题点击否。", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    base.Invoke(new MethodInvoker(delegate
                    {
                        base.WindowState           = FormWindowState.Maximized;
                        this.panelControl6.Height  = this.navBarControl1.Height * 4 / 5;
                        this.panelControl6.Visible = true;
                        this.xtraTabbedMdiManager1.Pages.Clear();
                        new FrmCheck(this.time)
                        {
                            MdiParent = this
                        }.Show();
                    }));
                    return;
                }
            }
        }
예제 #4
0
    public static bool RequestService(SocketInfoType socketInfoType, Package pkg)
    {
        int type = (int)socketInfoType;
        //if (ConnectToService(socketInfoType) == SERVICE_CODE.SUCCESS) //注掉这行代码 意味着用户需要显式连接后再发送
        {
            if (connectorMap.ContainsKey(type))
            {
                BaseSocket s = connectorMap[type];

                var sendBuff = PackageHelper.GetNetworkSendBuffer(pkg);
                if (s.SocketSend(sendBuff, 0, sendBuff.Length) == SOCKET_CODE.SUCCESS)
                {
                    return true;
                }
                else
                {
                    connectorMap.Remove(type);
                    return false;
                }
            }
        }

        return false;
    }
예제 #5
0
파일: SysManager.cs 프로젝트: ckbcjj/jxcar
        public static void SentToClient(List <ClientInfo> clientList, string TeacherNO, SocketInfoType type, object msg)
        {
            SocketInfo info = new SocketInfo {
                Name = TeacherNO,
                Type = type,
                Msg  = msg,
                Time = DateTime.Now
            };
            SendMessage item = new SendMessage {
                ClientList = clientList,
                socketInfo = info
            };

            lock (TcpService.SendMsgPool)
            {
                TcpService.SendMsgPool.Add(item);
            }
        }
예제 #6
0
 public ListenEventArgs(SocketInfoType type, object value)
 {
     this.value      = value;
     this._eventType = type;
 }
예제 #7
0
 public static SERVICE_CODE SetConfig(SocketInfoType socketInfoType, IpInfo info)
 {
     int socketType = (int)socketInfoType;
     AddrConfMap[socketType] = info;
     return SERVICE_CODE.SUCCESS;
 }
예제 #8
0
 public Service(SocketInfoType sType)
 {
     SocketInfoType = sType;
 }
예제 #9
0
 public Service()
 {
     SocketInfoType = SocketInfoType.TCPServer;
 }