Esempio n. 1
0
        private int sendFile(String filePath)
        {
            int i = SocketClientConnector.SendFile(socketClient, filePath, 102400, 1);

            Byte[] bytes  = new Byte[1024];
            int    len    = socketClient.Receive(bytes);
            String result = Encoding.Default.GetString(bytes, 0, len);

            if (!"".Equals(result))
            {
                String[] msg = System.Text.RegularExpressions.Regex.Split(result, "\\r\\n");

                if (msg.Length == 2)
                {
                    MessageBox.Show("文件解析成功!");
                    i = 0;
                }
                else
                {
                    MessageBox.Show("文件解析失败!错误信息:" + msg[1]);
                    i = -1;
                }
            }
            return(i);
        }
Esempio n. 2
0
        private int sendFile(String filePath)
        {
            int i = SocketClientConnector.SendFile(socketClient, filePath, 102400, 1);

            //if (i == 0) MessageBox.Show("文件  " + filePath + "  发送失败!");
            Byte[] bytes = new Byte[1024];
            int    len   = socketClient.Receive(bytes);
            //String result=System.Text.UTF8Encoding.UTF8.GetString(bytes);
            String result = Encoding.Default.GetString(bytes, 0, len);

            if (!"".Equals(result))
            {
                //result = result.Substring(8, result.Length-1);
                String[] msg = System.Text.RegularExpressions.Regex.Split(result, "\\r\\n");

                if (msg.Length == 2)
                {
                    MessageBox.Show("文件解析成功!");
                    i = 0;
                }
                else
                {
                    MessageBox.Show("文件解析失败!错误信息:" + msg[1]);
                    i = -1;
                }
            }
            //socketClient.Disconnect(false);
            //socketClient.Close();
            return(i);
        }
Esempio n. 3
0
        private void btn_send_Click(object sender, EventArgs e)
        {
            var aa = ConfigurationManager.AppSettings.Count;

            string[] getVal = new string[] { };
            foreach (var item in cblist.CheckedItems)
            {
                PokeGroupUIModel f = item as PokeGroupUIModel;
                getVal = ConfigurationManager.AppSettings[f.ConfigKey].Split(',');

                if (getVal.Count() > 0)
                {
                    f.IpAddress = getVal[0];
                    f.Port      = int.Parse(getVal[1]);
                }

                IPAddress  address      = IPAddress.Parse(f.IpAddress);
                IPEndPoint endpoint     = new IPEndPoint(address, f.Port);
                Socket     socketClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                socketClient.Connect(endpoint);
                int i = SocketClientConnector.SendFile(socketClient, f.ZipFile, 10000, 1);
                if (i == 0)
                {
                    MessageBox.Show(f.ZipFile + "文件发送成功");
                }
                else
                {
                    MessageBox.Show(f.ZipFile + "文件发送失败,i=" + i);
                }
            }
        }
Esempio n. 4
0
        private void btn_send_Click(object sender, EventArgs e)
        {
            string[] getVal = new string[] { };
            foreach (var item in cblist.CheckedItems)
            {
                PokeGroupUIModel f = item as PokeGroupUIModel;
                getVal = ConfigurationManager.AppSettings[f.ConfigKey].Split(';');

                if (getVal.Count() > 0)
                {
                    f.IpAddress = getVal[0];
                    f.Port      = int.Parse(getVal[1]);
                }
                if (f.ZipFile == null)
                {
                    continue;
                }
                IPAddress  address      = IPAddress.Parse(f.IpAddress);
                IPEndPoint endpoint     = new IPEndPoint(address, f.Port);
                Socket     socketClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                socketClient.Connect(endpoint);
                int i = SocketClientConnector.SendFile(socketClient, f.ZipFile, 102400, 1);

                if (i == 0)
                {
                    MessageBox.Show(f.ZipFile + "文件发送成功");
                    Byte[] bytes = new Byte[1024];
                    socketClient.Receive(bytes);
                    System.Text.UTF8Encoding.UTF8.GetString(bytes);
                    socketClient.Disconnect(false);
                    socketClient.Close();
                }
                else
                {
                    MessageBox.Show(f.ZipFile + "文件发送失败,i=" + i);
                }
            }
        }