You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.3 KiB
C#

using AUCMA.STORE.Common;
using AUCMA.STORE.Entity.DAO;
using AUCMA.STORE.Entity.DTO;
using Nancy.Json;
using NetworkCommsDotNet;
using NetworkCommsDotNet.Connections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace AUCMA.STORE.NetWork
{
public class NetWorkServer
{
private static JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
public delegate void BaseMaterialInfoRefresh(BaseMaterialDTO baseMaterialDTO);
public static event BaseMaterialInfoRefresh BaseMaterialInfoRefreshEvent;
public static void init()
{
// IP地址和端口
IPEndPoint thePoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), int.Parse("1212"));
//开始监听此IP和端口 使用TCP协议
Connection.StartListening(ConnectionType.TCP, thePoint);
//关联消息类型为GetName的消息的处理方法
NetworkComms.AppendGlobalIncomingPacketHandler<string>("GetName", IncomingMsgHandle);
Console.WriteLine("已经开始监听");
}
public static void IncomingMsgHandle(PacketHeader header, Connection connection, string msg)
{
//获取队列数据 ,出库
if (msg.Equals("123"))
{
connection.SendObject("ResName", JsonChange.ModeToJson(TaskDictionary.getOutDictionary()));
return;
}
//入库
if (msg.Equals("456"))
{
connection.SendObject("ResName", JsonChange.ModeToJson(TaskDictionary.getInDictionary()));
return;
}
//手动任务
if (msg.Equals("789"))
{
connection.SendObject("ResName", JsonChange.ModeToJson(TaskDictionary.getOtherDictionary()));
return;
}
connection.SendObject("ResName", msg);
BaseMaterialDTO baseMaterialDTO = javaScriptSerializer.Deserialize<BaseMaterialDTO>(msg);
if (BaseMaterialInfoRefreshEvent != null)
{
BaseMaterialInfoRefreshEvent(baseMaterialDTO);
}
}
}
}