init
This commit is contained in:
parent
e98fbeadfd
commit
1281b1c854
Binary file not shown.
|
@ -3,4 +3,30 @@
|
|||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||
</startup>
|
||||
<log4net>
|
||||
<root>
|
||||
<level value="ALL" />
|
||||
<appender-ref ref="SysAppender" />
|
||||
</root>
|
||||
<logger name="WebLogger">
|
||||
<level value="DEBUG" />
|
||||
</logger>
|
||||
<appender name="SysAppender" type="log4net.Appender.RollingFileAppender,log4net">
|
||||
<param name="File" value="App_Data/" />
|
||||
<param name="AppendToFile" value="true" />
|
||||
<param name="RollingStyle" value="Date" />
|
||||
<param name="DatePattern" value=""Logs_"yyyyMMdd".txt"" />
|
||||
<param name="StaticLogFileName" value="false" />
|
||||
<layout type="log4net.Layout.PatternLayout,log4net">
|
||||
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
|
||||
<param name="Header" value=" ------------------------------------------------
" />
|
||||
<param name="Footer" value=" ------------------------------------------------
" />
|
||||
</layout>
|
||||
</appender>
|
||||
<appender name="consoleApp" type="log4net.Appender.ConsoleAppender,log4net">
|
||||
<layout type="log4net.Layout.PatternLayout,log4net">
|
||||
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
</log4net>
|
||||
</configuration>
|
|
@ -33,6 +33,9 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<HintPath>packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
|
@ -44,11 +47,12 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ToolKit.cs" />
|
||||
<Compile Include="dianbiao.cs" />
|
||||
<Compile Include="Dianbiao.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -3,14 +3,81 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using ToolKitlib;
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
|
||||
namespace DianBiao
|
||||
{
|
||||
class dianbiao
|
||||
class Dianbiao
|
||||
{
|
||||
static log4net.ILog log;//日志插件
|
||||
|
||||
public static Socket udpServer;//udp服务器
|
||||
public static bool memberReply;//是否回复消息
|
||||
public static int length = 0;//接收数据长度
|
||||
|
||||
public static EndPoint serverEnd; //服务端
|
||||
public static IPEndPoint ipEnd; //发送消息服务端
|
||||
public static Socket socket; //目标socket
|
||||
public static Thread connectThread; //连接线程
|
||||
public static byte[] sendData;//发送的数据
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
//初始化日志
|
||||
log4net.Config.XmlConfigurator.Configure();
|
||||
log = log4net.LogManager.GetLogger("loginfo");
|
||||
init();
|
||||
while (true)
|
||||
{
|
||||
Thread.Sleep(10000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void init()
|
||||
{
|
||||
try
|
||||
{
|
||||
//var IP = "111.229.30.246";
|
||||
|
||||
var IP = "172.17.0.9";
|
||||
//string IP = "172.16.1.49";
|
||||
int Port = 12302;
|
||||
|
||||
//建立udp服务器,参数2:udp协议以数据报的方式传输,参数3:UDP协议
|
||||
udpServer = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
||||
//为服务器绑定IP
|
||||
IPAddress ip = IPAddress.Parse(IP);
|
||||
EndPoint ep = new IPEndPoint(ip, Port);
|
||||
udpServer.Bind(ep);
|
||||
//接收数据
|
||||
EndPoint endP = new IPEndPoint(IPAddress.Any, 0);
|
||||
|
||||
string message;
|
||||
byte[] data = new byte[1024 * 1024 * 2];
|
||||
length = 0;
|
||||
//把数据的来源放到第二个参数上
|
||||
while (true)
|
||||
{
|
||||
length = udpServer.ReceiveFrom(data, ref endP);
|
||||
//message = Encoding.Default.GetString(data, 0, length);
|
||||
message = ToolKit.byteArrayToHexString(data, length);
|
||||
log.Info("接收到 " + endP.ToString() + ": " + message);
|
||||
message = message.Replace(" ", "");
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Console.WriteLine("接收初始化:" + e.Message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="log4net" version="2.0.8" targetFramework="net472" />
|
||||
</packages>
|
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue