• 大小: 70KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-09
  • 语言: 其他
  • 标签: 多线程  UDP  储存  

资源简介

多线程UDP接收到数据,并对数据进行存储

资源截图

代码片段和文件信息

using System;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace Gps.MonitorService
{
    public class MonitorServer
    {
         private static UdpClient listener;
         private IPAddress IPAddr;
         private const int port = 8080;
         private Thread listenerThread = null;

         public MonitorServer(string IP)
         {
             this.IPAddr = IPAddress.Parse(IP);
         }

         private static void WriteLog(string ex)
         {
             string path = @System.Environment.CurrentDirectory;

             try
             {
                 if (Directory.Exists(path))
                 {
                     string filename = path + “Error.txt“;
                     FileInfo myfile = new FileInfo(filename);
                     if (!myfile.Exists)
                     {
                         FileStream newfile = myfile.OpenWrite();
                         newfile.Close();
                     }

                     StreamWriter write = new StreamWriter(filename true);
                     write.WriteLine(ex);
                     write.Flush();
                     write.Close();
                 }
                 else
                 {
                     Directory.CreateDirectory(path);
                     string filename = path + “Error.txt“;

                     FileStream newfile = File.Create(filename);
                     newfile.Flush();
                     newfile.Close();
                     StreamWriter write = new StreamWriter(filename);
                     write.WriteLine(ex);
                     write.Flush();
                     write.Close();
                 }
             }
             catch (Exception ex1)
             {
                 
             }
         }

         private static void SaveMessage(string mgs)
         {
             string path = @System.Environment.CurrentDirectory;

             try
             {
                 if (Directory.Exists(path))
                 {
                     string filename = path + “Message.txt“;
                     FileInfo myfile = new FileInfo(filename);
                     if (!myfile.Exists)
                     {
                         FileStream newfile = myfile.OpenWrite();
                         newfile.Close();
                     }

                     StreamWriter write = new StreamWriter(filename true);
                     write.WriteLine(mgs);
                     write.Flush();
                     write.Close();
                 }
                 else
                 {
                     Directory.CreateDirectory(path);
                     string filename = path + “Message.txt“;

                     FileStream newfile = File.Create(filename);
                     newfile.Flush();
                     newfile.Close();
                     StreamWrit

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1426  2016-08-04 16:17  Monitor\Backup\GPS_Monitor.sln

    ..A..H.     39424  2016-08-28 18:07  Monitor\Backup\GPS_Monitor.suo

     文件       5052  2016-08-28 17:48  Monitor\Backup\WindowsServer\MonitorServer.cs

     文件       2515  2016-08-04 16:33  Monitor\Backup\WindowsServer\MonitorServer.csproj

     文件       1358  2016-08-01 14:41  Monitor\Backup\WindowsServer\Properties\AssemblyInfo.cs

     文件        544  2016-08-01 14:42  Monitor\Backup\WindowsService1\MonitorService.cs

     文件       2776  2016-08-01 14:48  Monitor\Backup\WindowsService1\MonitorService.csproj

     文件       1099  2016-08-01 14:43  Monitor\Backup\WindowsService1\MonitorService.Designer.cs

     文件        518  2016-08-01 14:44  Monitor\Backup\WindowsService1\Program.cs

     文件       1362  2016-08-01 14:36  Monitor\Backup\WindowsService1\Properties\AssemblyInfo.cs

     文件       1426  2016-08-30 15:27  Monitor\GPS_Monitor.sln

    ..A..H.     47616  2016-09-11 18:09  Monitor\GPS_Monitor.suo

     文件       3799  2016-08-30 15:27  Monitor\UpgradeLog.xml

     文件       4096  2016-08-01 14:48  Monitor\WindowsServer\bin\Debug\ClassLibrary1.dll

     文件       7680  2016-08-01 14:48  Monitor\WindowsServer\bin\Debug\ClassLibrary1.pdb

     文件       6144  2016-09-11 17:46  Monitor\WindowsServer\bin\Debug\MonitorService.dll

     文件      17920  2016-09-11 17:46  Monitor\WindowsServer\bin\Debug\MonitorService.pdb

     文件       5052  2016-08-28 17:48  Monitor\WindowsServer\MonitorServer.cs

     文件       4176  2016-08-30 15:27  Monitor\WindowsServer\MonitorServer.csproj

     文件        452  2016-08-30 15:27  Monitor\WindowsServer\MonitorServer.csproj.user

     文件        538  2016-08-01 14:42  Monitor\WindowsServer\obj\Debug\ClassLibrary1.csproj.FileListAbsolute.txt

     文件       4096  2016-08-01 14:48  Monitor\WindowsServer\obj\Debug\ClassLibrary1.dll

     文件       5791  2016-09-11 17:46  Monitor\WindowsServer\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1428  2016-09-11 17:46  Monitor\WindowsServer\obj\Debug\MonitorServer.csproj.FileListAbsolute.txt

     文件       6144  2016-09-11 17:46  Monitor\WindowsServer\obj\Debug\MonitorService.dll

     文件      17920  2016-09-11 17:46  Monitor\WindowsServer\obj\Debug\MonitorService.pdb

     文件       4096  2016-08-04 16:24  Monitor\WindowsServer\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件       1358  2016-08-01 14:41  Monitor\WindowsServer\Properties\AssemblyInfo.cs

     文件       5120  2016-09-11 17:45  Monitor\WindowsService1\bin\Debug\WindowsService1.exe

     文件      19968  2016-09-11 17:45  Monitor\WindowsService1\bin\Debug\WindowsService1.pdb

............此处省略46个文件信息

评论

共有 条评论