Esempio n. 1
0
        private void asyncread(TcpClient sock)
        {
            Tclient tcpclient = new Tclient();

            tcpclient.clien = sock;

            tcpclient.stream = sock.GetStream();
            if (tcpclient.stream.CanRead)
            {
                try
                {
                    IAsyncResult ar = tcpclient.stream.BeginRead(tcpclient.buffer, 0, Tclient.bufferSize, new AsyncCallback(TCPReadCallBack), tcpclient);
                }
                catch (Exception ex)
                {
                    Prompt.Log.Info(ex.Message);
                }
            }
        }
Esempio n. 2
0
        private void TCPReadCallBack(IAsyncResult ar)
        {
            Tclient state = (Tclient)ar.AsyncState;

            if (state.clien == null || !state.clien.Connected)
            {
                return;
            }
            int           rec;
            NetworkStream steam = state.stream;

            rec = state.stream.EndRead(ar);
            state.totalCount += rec;
            if (rec > 0)
            {
                if (state.stream.CanRead)
                {
                    byte[] bytedata = new byte[rec];
                    Array.Copy(state.buffer, 0, bytedata, 0, rec);
                    string data = BitConverter.ToString(bytedata);
                    data = Encoding.ASCII.GetString(bytedata);

                    string[] tmp = data.Split(',');
                    if ((decimal.TryParse(tmp[0], out decimal d_tmp_x)) && (decimal.TryParse(tmp[1], out decimal d_tmp_y)))
                    {
                        Receive_Cordinate = new Vector(d_tmp_x, d_tmp_y);
                        Rec_Ok            = true;
                        MessageBox.Show(string.Format("(X:{0},Y:{1})", Receive_Cordinate.X, Receive_Cordinate.Y));
                    }
                    else
                    {
                        MessageBox.Show("相机坐标提取格式失败!!!!");
                    }
                    //Senddata(Bis_result);
                    state.stream.BeginRead(state.buffer, 0, Tclient.bufferSize, new AsyncCallback(TCPReadCallBack), state);
                }
            }