You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.7 KiB
56 lines
1.7 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Xml;
|
|
using System.IO;
|
|
|
|
namespace SocketProgram
|
|
{
|
|
public static class SocketClass
|
|
{
|
|
//获取当前时间毫秒字符串
|
|
public static string GetNowTimeStr() {
|
|
long currentTicks = DateTime.Now.ToUniversalTime().Ticks;
|
|
DateTime dtFrom = new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
|
long currentMillis = ((currentTicks - dtFrom.Ticks) / 10000) % 1000;
|
|
string str = DateTime.Now.ToString() + "[" + currentMillis + "]";
|
|
return str;
|
|
}
|
|
//写文件
|
|
public static void WriteLog(string filePath, string str)
|
|
{
|
|
using (StreamWriter sw = new StreamWriter(filePath,true))
|
|
{
|
|
sw.WriteLine(str);
|
|
}
|
|
}
|
|
//读文件
|
|
public static string[] ReadTxt(string filePath)
|
|
{
|
|
string[] res = { "","",""};
|
|
using (StreamReader sr = new StreamReader(filePath))
|
|
{
|
|
string line = "";
|
|
int i = 0;
|
|
while (((line = sr.ReadLine()) != null) & (i<3))
|
|
{
|
|
res[i++] = line;
|
|
}
|
|
}
|
|
return res;
|
|
}
|
|
//记录收到的内容
|
|
public static void DealRecvMsg(string filePath, string info, bool recordNow)
|
|
{
|
|
string recvInfo = "recvInfo:" + info;
|
|
string recvTime = "recv_time:" + SocketClass.GetNowTimeStr();
|
|
SocketClass.WriteLog(filePath, recvInfo);
|
|
if (recordNow)
|
|
{
|
|
SocketClass.WriteLog(filePath, recvTime);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|