Ejemplo n.º 1
0
        private static void sendLoginMessage()
        {
            StreamPackage <LoginMessage> loginPost = new StreamPackage <LoginMessage>();

            loginPost.Command  = Command.Login;
            loginPost.Data.UID = Tools.RndInt(10000, 99999);
            client.Send(loginPost.DataBytes());
        }
Ejemplo n.º 2
0
        private void buttonDebug2_Click(object sender, EventArgs e)
        {
            AsyncSocketClient client = new AsyncSocketClient();

            client.Connect("127.0.0.1", (int)numericUpDown1.Value);
            client.Send("hello", Encoding.Unicode);
        }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        Transform t = GetComponentInParent <Transform>();

        for (int i = 0; i < solarPanels.Length; i++)
        {
            SolarPanel panel       = solarPanels[i];
            float      adjustValue = panel.adjust_value;

            if (!disable)
            {
                panel.transform.Rotate(Vector3.right * adjustValue);
            }

            float elapsed_time = Time.time - start_time;
            elapsed_delta += Time.deltaTime;

            if (socket.connected && elapsed_delta > 0.05)
            {
                //float solar_angle     = Vector3.SignedAngle(panel.resting_pos.forward, panel.calculated_solar_dir,                        transform.right);
                float actualSolarAngle = Vector3.SignedAngle(panel.resting_pos.forward, sun.transform.position - panel.transform.position, transform.right);

                elapsed_delta = 0;
                //string msg = "{ \"adjust_value\": { \"time\":" + elapsed_time.ToString().Replace(",", ".") + ", \"value\": "+ adjustValue.ToString().Replace(",", ".")+"} }";
                string msg = "{ \"adjust_value_" + i + "\": " + adjustValue.ToString().Replace(",", ".") + " , \"actual_angle_" + i + "\": " + panel.current_offset_angle.ToString().Replace(",", ".") + ", \"desired_position_" + i + "\": " + panel.desired_position.ToString().Replace(",", ".") + ", \"actual_solar_angle_" + i + "\": " + actualSolarAngle.ToString().Replace(",", ".") + "}";

                socket.Send(msg);
            }
            logWriters[i].WriteLine(elapsed_time.ToString().Replace(",", ".") + "," + adjustValue.ToString().Replace(",", "."));
        }
    }
Ejemplo n.º 4
0
    // Start is called before the first frame update
    void Start()
    {
        solarPanels = GetComponentsInChildren <SolarPanel>();
        logWriters  = new LogWriter[solarPanels.Length];

        for (int i = 0; i < logWriters.Length; i++)
        {
            logWriters[i] = new LogWriter("panel_" + i + ".csv");

            if (logWriters[i].Length() == 0)
            {
                logWriters[i].WriteLine("time,value");
            }
        }

        socket = FindObjectOfType <NetworkHandler>().client;

        socket.On("connect", () =>
        {
            string[] available_data = new string[solarPanels.Length];
            for (int i = 0; i < solarPanels.Length; i++)
            {
                available_data[i] = "\"adjust_value_" + i + "\":\"float\", \"actual_angle_" + i + "\":\"float\", \"desired_position_" + i + "\":\"float\", \"actual_solar_angle_" + i + "\":\"float\"";
            }
            socket.Send("{\"available_data\": {" + string.Join(",", available_data) + "}}");
        });

        socket.On("message", () =>
        {
        });
        start_time = Time.time;

        sun = GameObject.FindGameObjectWithTag("sun");
    }
Ejemplo n.º 5
0
        private void HeartBeat()
        {
            DateTime dtlast = DateTime.Now.AddSeconds(-1000);

            while (heartThreadRun)
            {
                Thread.Sleep(1000);
                if ((DateTime.Now - dtlast).TotalSeconds > cfg.HeartBeatTimeOutSecond)
                {
                    dtlast = DateTime.Now;
                    asyncClient.Send("HEART");
                    SendText("HEART");
                }
            }
        }
Ejemplo n.º 6
0
        // 체커로의 연결을 확인
        void CheckChecker()
        {
            //LogManager.Instance.Log("체커 연결 확인");

            bool bNeedConnection = false;

            if (checker_socket_ == null)
            {
                bNeedConnection = true;
            }
            else
            {
                if (checker_socket_.Connection == null)
                {
                    bNeedConnection = true;
                }
                else
                {
                    if (checker_socket_.Connection.Connected == false)
                    {
                        bNeedConnection = true;
                    }
                    else
                    {
                        LQCrawlerInfo    pInfo = CrawlerManager.Instance.GetCrawlerInfo();
                        C_TO_K_HEARTBEAT p     = new C_TO_K_HEARTBEAT();
                        p.num           = (byte)PACKET_IDX.CK_HEARTBEAT;
                        p.len           = (Int16)Marshal.SizeOf(p);
                        p.CrawlingCount = CrawlerManager.Instance.CrawlingCount();
                        byte[] sendbuffer = new byte[p.len];
                        PacketProcess.Serialize(p, sendbuffer);
                        checker_socket_.Send(sendbuffer);
                    }
                }
            }

            if (bNeedConnection == true)
            {
                CheckerConnect();
            }
        }
Ejemplo n.º 7
0
        // 매니저의 연결을 확인
        void CheckManager()
        {
            bool bNeedConnection = false;

            if (manager_socket_ == null)
            {
                bNeedConnection = true;
            }
            else
            {
                if (manager_socket_.Connection == null)
                {
                    bNeedConnection = true;
                }
                else
                {
                    if (manager_socket_.Connection.Connected == false)
                    {
                        bNeedConnection = true;
                    }
                    else
                    {
                        LQCrawlerInfo      pInfo = CrawlerManager.Instance.GetCrawlerInfo();
                        C_TO_M_CHANNEL_IDX p     = new C_TO_M_CHANNEL_IDX();
                        p.num  = (byte)PACKET_IDX.CM_CHANNEL_IDX;
                        p.len  = (Int16)Marshal.SizeOf(p);
                        p.nIdx = pInfo.nIdx_;
                        byte[] sendbuffer = new byte[p.len];
                        PacketProcess.Serialize(p, sendbuffer);
                        manager_socket_.Send(sendbuffer);
                    }
                }
            }

            if (bNeedConnection == true)
            {
                ManagerConnect();
            }
        }
Ejemplo n.º 8
0
        private void dataGridView_Crawler_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 8)
            {
                string str    = dataGridView_Crawler.Rows[e.RowIndex].Cells[0].Value as string;
                Int32  nChIdx = Convert.ToInt32(str);
                if (AppManager.Instance.Checker_Connection_List_.ContainsKey(nChIdx) == true)
                {
                    AsyncSocketClient psocket = AppManager.Instance.Checker_Connection_List_[nChIdx];

                    M_TO_K_RESTART p = new M_TO_K_RESTART();
                    p.num = (byte)PACKET_IDX.MK_RESTART;
                    p.len = (Int16)Marshal.SizeOf(p);
                    byte[] sendbuffer = new byte[p.len];
                    PacketProcess.Serialize(p, sendbuffer);

                    psocket.Send(sendbuffer);
                }
                else
                {
                    MessageBox.Show("체커와 연결이되지 않았습니다. 체커를 실행 시켜 주세요.");
                }
            }
        }
Ejemplo n.º 9
0
 public void Send(string data)
 {
     client.Send(data + "\n");
 }