49 lines
1.7 KiB
Plaintext
49 lines
1.7 KiB
Plaintext
|
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();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|