private void StartReceive()
{
string msg = null;
IPEndPoint iep = new IPEndPoint(IPAddress.Parse(PublicVariables.BJIP), PublicVariables.PORT);
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Bind(iep);
socket.Listen(PublicVariables.JTS);
Socket newSocket;
while (true)
{
try
{
newSocket = socket.Accept();
byte[] byteMessage = new byte[1024 * 1024];
int js = 1;
js = newSocket.Receive(byteMessage, byteMessage.Length, 0);
Console.WriteLine(js);
msg = Encoding.UTF8.GetString(byteMessage);
msg = msg.Replace("\0", "");
PostGetData pgd = new PostGetData();
string cz = msg.Substring(0, 4);
if (cz.Equals("gxsj"))
{
NetworkStream stream = new NetworkStream(newSocket);
bool result = pgd.SendFile("caipu.db3", stream);
stream.Close();
newSocket.Dispose();
msg = null;
}
else if (cz.Equals("gkkt"))
{
string ctInfo = null;
byte[] bytes = null;
ctInfo = pgd.GetCtInfo();
bytes = new byte[1024 * 1024];
bytes = Encoding.UTF8.GetBytes(ctInfo);
newSocket.Send(bytes);
//newSocket.Close();
newSocket.Dispose();
msg = null;
}
else if (cz.Equals("gxtp"))
{
NetworkStream stream = new NetworkStream(newSocket);
bool result = pgd.FsFile("image.zip", stream);
stream.Close();
newSocket.Close();
newSocket.Dispose();
msg = null;
}
else if (cz.Equals("gkdc"))
{
string data = msg.Substring(6);
Regex regex = new Regex("<<");
string[] strs = regex.Split(data);
SqlHelper helper = new SqlHelper();
byte[] bytes = new byte[1024 * 1024];
try
{
string result = helper.Gkdc(strs);
bytes = Encoding.UTF8.GetBytes(result);
if (newSocket.Connected)
{
newSocket.Send(bytes);
}
newSocket.Dispose();
msg = null;
}
catch
{
bytes = Encoding.UTF8.GetBytes("error");
if (newSocket.Connected)
{
newSocket.Send(bytes);
}
newSocket.Dispose();
msg = null;
continue;
}
}
else if (cz.Equals("ckxf"))
{
string[] strs = msg.Split('@');
string str = strs[0].Substring(6);
SqlHelper helper = new SqlHelper();
string result = helper.ckxf(str);
NetworkStream stream = new NetworkStream(newSocket);
bool results = pgd.FsFile(str + ".log", stream);
stream.Close();
newSocket.Dispose();
msg = null;
}
else if (cz.Equals("gqcp"))
{
SqlHelper helper = new SqlHelper();
List<string> lists = helper.gqcp();
TxtFileManager tfm = new TxtFileManager();
tfm.DelFile("gqcp.log");
if (lists.Count > 0)
{
for (int i = 0; i < lists.Count; i++)
{
tfm.Write("gqcp.log", lists[i].ToString());
}
}
else
{
tfm.Write("gqcp.log", "null");
}
NetworkStream stream = new NetworkStream(newSocket);
bool results = pgd.FsFile("gqcp.log", stream);
stream.Close();
newSocket.Dispose();
msg = null;
}
else if (cz.Equals("tcsl"))
{
string data = msg.Substring(6);
Regex regex = new Regex("<<");
string[] strs = regex.Split(data);
SqlHelper helper = new SqlHelper();
string result = helper.GetTcsl(strs[0], strs[1], strs[2]);
byte[] bytes = new byte[1024 * 1024];
bytes = Encoding.UTF8.GetBytes(result);
newSocket.Send(bytes);
newSocket.Dispose();
msg = null;
}
else if (cz.Equals("gktc"))
{
string data = msg.Substring(6);
Regex regex = new Regex("<<");
string[] strs = regex.Split(data);
SqlHelper helper = new SqlHelper();
string result = helper.Gktc(strs);
byte[] bytes = new byte[1024 * 1024];
bytes = Encoding.UTF8.GetBytes(result);
newSocket.Send(bytes);
newSocket.Dispose();
msg = null;
}
}
catch (Exception ex)
{
TxtFileManager tfm = new TxtFileManager();
tfm.Write("sys.log", ex.ToString() + " " + DateTime.Now.ToString());
continue;
}
}
}