• 大小: 133KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-16
  • 语言: C#
  • 标签: GPRS  C#  SOCKET  SQL  通讯  

资源简介

使用SOCKET技术实现终端和服务器的远程通讯,运用GPRS模块基于TCP/IP协议,实现服务器远程访问终端,并将接受到的数据下载存储到数据库

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Data.SqlClient;
using System.Timers;


namespace asynserver
{
    public partial class Form1 : Form
    {
        struct ClientInfo
        {
            public Socket socket; //socket of client
            public DateTime time; // 最近一次通信成功的时间
        }

        delegate void SetTextCallback(string text);
        int flag = 0;

        DateTime yuyang_datatime = new DateTime();  //用于记录最近一次各站点接收到数据的时间
        DateTime jinshu_datatime = new DateTime();  

        private IPEndPoint myserverip;
        private Socket mysocket;
       // private Socket handler;
        private ArrayList clientlist = new ArrayList();

        byte[] byteDataRece = new byte[1024];
       
        public Form1()
        {
            InitializeComponent();
            
            //获取当前主机IP值
            IPHostEntry   ipHostInfo   =    Dns.GetHostEntry(Dns.GetHostName());
            IPAddress ipAddress = ipHostInfo.AddressList[0];   
          //  IPAddress ipAddress = ipHostInfo.AddressList[1];   

          //  serverip.Text = “192.168.10.3“;
            serverip.Text = ipAddress.ToString();
            duankouhao.Text = “8060“;

            checktimer.Enabled = true;
            checktimer.Start();
                      
        }

        private void btnsend_Click(object sender EventArgs e)
        {
            //byte[] bytedata = Encoding.BigEndianUnicode.GetBytes(message.Text);
            byte[] bytedata = Encoding.ASCII.GetBytes(message.Text);
            message.Clear();

            byte[] crcjieguo = CRC16(bytedatabytedata.Length);
            //转换为十六进制
            string ddd = BitConverter.ToString(crcjieguo);

           
        }

        private void btnclose_Click(object sender EventArgs e)
        {
            //关闭定时器
            checktimer.Stop();

           liststate.Items.Add(“主机监听停止“);
        }

        private void btnjianting_Click(object sender EventArgs e)
        {
            
            //点击完监听按钮后,使按钮失效
            btnjianting.Enabled = false;                          

            myserverip = new IPEndPoint(IPAddress.Parse(serverip.Text)Int32.Parse(duankouhao.Text));
            mysocket = new Socket(AddressFamily.InterNetworkSocketType.StreamProtocolType.Tcp);
            mysocket.Bind(myserverip);
            mysocket.Listen(20);
            liststate.Items.Add(“主机开始监听···“);

            //主服务器线程
            Thread thread = new Thread(new ThreadStart(target));  
            thread.Start();              
        }

        private void target()
        {          
                try
                {                       
                  mysocket.BeginAccept

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2011-10-14 09:48  asynserver\
     目录           0  2011-10-14 09:48  asynserver\asynserver\
     文件         920  2010-05-19 09:02  asynserver\asynserver.sln
     文件       43520  2011-09-05 22:13  asynserver\asynserver.suo
     文件        3477  2010-05-19 09:02  asynserver\asynserver\asynserver.csproj
     目录           0  2011-10-14 09:48  asynserver\asynserver\bin\
     目录           0  2011-10-14 09:48  asynserver\asynserver\bin\Debug\
     文件       24576  2011-03-29 19:05  asynserver\asynserver\bin\Debug\asynserver.exe
     文件       60928  2011-03-29 19:05  asynserver\asynserver\bin\Debug\asynserver.pdb
     文件       14328  2011-09-05 21:51  asynserver\asynserver\bin\Debug\asynserver.vshost.exe
     文件         490  2007-07-21 01:33  asynserver\asynserver\bin\Debug\asynserver.vshost.exe.manifest
     文件       36864  2009-12-21 20:25  asynserver\asynserver\bin\Debug\asynserver1220.exe
     文件       37668  2011-03-29 19:05  asynserver\asynserver\Form1.cs
     文件        9820  2011-03-29 19:05  asynserver\asynserver\Form1.Designer.cs
     文件        6012  2011-03-29 19:05  asynserver\asynserver\Form1.resx
     目录           0  2011-10-14 09:48  asynserver\asynserver\obj\
     文件         289  2009-12-07 12:00  asynserver\asynserver\obj\asynserver.csproj.FileList.txt
     文件        3572  2009-12-28 22:43  asynserver\asynserver\obj\asynserver.csproj.FileListAbsolute.txt
     目录           0  2011-10-14 09:48  asynserver\asynserver\obj\Debug\
     文件        2046  2011-09-05 21:51  asynserver\asynserver\obj\Debug\asynserver.csproj.FileListAbsolute.txt
     文件         847  2011-03-29 19:05  asynserver\asynserver\obj\Debug\asynserver.csproj.GenerateResource.Cache
     文件       24576  2011-03-29 19:05  asynserver\asynserver\obj\Debug\asynserver.exe
     文件         180  2011-03-29 19:05  asynserver\asynserver\obj\Debug\asynserver.Form1.resources
     文件       60928  2011-03-29 19:05  asynserver\asynserver\obj\Debug\asynserver.pdb
     文件         180  2011-03-29 10:19  asynserver\asynserver\obj\Debug\asynserver.Properties.Resources.resources
     目录           0  2011-10-13 22:32  asynserver\asynserver\obj\Debug\Refactor\
     目录           0  2011-10-14 09:48  asynserver\asynserver\obj\Debug\TempPE\
     文件        4608  2010-05-19 09:02  asynserver\asynserver\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll
     文件         469  2009-04-11 21:46  asynserver\asynserver\Program.cs
     目录           0  2011-10-14 09:48  asynserver\asynserver\Properties\
     文件        1192  2009-04-11 21:46  asynserver\asynserver\Properties\AssemblyInfo.cs
............此处省略28个文件信息

评论

共有 条评论