SafeNet/.svn/pristine/3c/3ce17ec0d259c3c9d8ab813df20b357b84d6eb23.svn-base

49 lines
1.7 KiB
Plaintext
Raw Normal View History

2021-02-24 11:50:23 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using SafeNetLib;
namespace Teltonika_SOC
{
class LocationThread
{
public int port;
private TcpListener server;
// -------------------------------------------------------------------
// Main
// -------------------------------------------------------------------
public LocationThread()
{
// init the TCP client listener
Utils.ConsWrite(DebugMSG_Type.Debug, " Location Thread created ....");
server = new TcpListener(System.Net.IPAddress.Any, Program.cfg.locPort);
server.Start();
Utils.ConsWrite(DebugMSG_Type.Debug, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
Utils.ConsWrite(DebugMSG_Type.Debug, "Location Thread listennig on port:" + Program.cfg.locPort);
Utils.ConsWrite(DebugMSG_Type.Debug, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
}
public void HandleConnection()
{
while (true)
{
while (!server.Pending())
{
Thread.Sleep(1000);
}
//assign new thread for each connection
ConnectionThread newconnection = new ConnectionThread();
newconnection.client = server.AcceptTcpClient();
Thread newthread = new Thread(new ThreadStart(newconnection.HandleConnection));
newthread.IsBackground = true;
newthread.Start();
}
}
}
}