예제 #1
0
        //private void Accept(IAsyncResult lsocket)
        //{
        //    Socket lss = (Socket)lsocket;
        //    Socket newclient = lss.EndAccept(lsocket);
        //    IPAddress temclip = ((IPEndPoint)lss.RemoteEndPoint).Address;
        //    int pt = ((IPEndPoint)lss.RemoteEndPoint).Port;
        //    chart temchart = new chart(num.ToString(), temclip, newclient,pt);
        //    temchart.Show();
        //    common.charts.Add(num.ToString(), temchart);
        //    num++;
        //    //clientitems.Add(num, newclient);
        //    //ParameterizedThreadStart pts = new ParameterizedThreadStart(recv);
        //    //Thread clth = new Thread(pts);
        //    //clth.Start(newclient);

        //    lss.BeginAccept(new AsyncCallback(Accept), listensocket);
        //}

        #endregion

        private void button_chart_Click(object sender, EventArgs e)
        {
            int    index = dataGridView_one.CurrentRow.Index;
            string IP    = (string)dataGridView_one.Rows[index].Cells[2].Value;
            string state = (string)dataGridView_one.Rows[index].Cells[1].Value;
            string ID    = (string)dataGridView_one.Rows[index].Cells[0].Value;

            if (state == "在线")
            {
                if (common.charts.ContainsKey(ID))
                {
                    common.charts[ID].Show();
                }
                else
                {
                    Console.WriteLine(getport(ID));
                    Socket newclient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    chart  temchart  = new chart(ID, IPAddress.Parse(IP), newclient, getport(ID));
                    temchart.Show();
                    temchart.Text = ID;
                    common.charts.Add(ID, temchart);
                    num++;
                }
            }
        }
예제 #2
0
        public void shutcon()
        {
            chart temchart = null;

            foreach (var value in common.charts)
            {
                temchart = value.Value;
                temchart.shutcon(false);
                temchart.Dispose();
            }
            common.charts.Clear();
        }
예제 #3
0
        private void onconnect(object state)
        {
            Socket newclient = (Socket)state;

            int    length = newclient.Receive(rcfmsgbuffer);
            string rcfmsg = Encoding.UTF8.GetString(rcfmsgbuffer, 0, length);
            string label  = rcfmsg.Substring(0, 4);

            switch (label)
            {
            case "*//*":
                string temchaername = rcfmsg.Substring(4);
                common.charts[temchaername].startfiletrans(newclient);
                break;

            case "-**-":
                newclient.Close();
                this.listensocket.Close();
                break;

            default:
                int index = rcfmsg.IndexOf("*++");
                recevieID = rcfmsg.Substring(0, index);
                Console.WriteLine(recevieID);
                Console.WriteLine(rcfmsg);
                rcfmsg = rcfmsg.Substring(index + 3);
                if (common.charts.ContainsKey(recevieID))
                {
                    common.charts[recevieID].changesockets(newclient, rcfmsg);
                }
                else
                {
                    chart temchart = new chart(recevieID, newclient, rcfmsg);
                    temchart.Show();
                    common.charts.Add(recevieID, temchart);
                }
                break;
            }
        }