using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Sockets; using System.Threading; using System.Net; using System.Collections; using System.Diagnostics; namespace WindowsService1 { class RegistrationThread { int port; private Socket socket; public RegistrationThread(int registrationPort) { port = registrationPort; } public void handleConnection() { EventLog.WriteEntry("Safemobile", "Registration Thread - Initialized on Port " + port, EventLogEntryType.Information, 34500); TcpListener myListener = new TcpListener(IPAddress.Any, port); myListener.Start(); while (true) { try { socket = myListener.AcceptSocket(); String clientIP = ((IPEndPoint)socket.RemoteEndPoint).Address.ToString(); EventLog.WriteEntry("Safemobile", "IP " + clientIP + " connected", EventLogEntryType.Information, 34500); //Form1.TCPsocket = socket; Service1.listOFSocket.Add(socket); ReadThread RegistrationConnection = new ReadThread(socket); Thread LocationThreadObj = new Thread(new ThreadStart(RegistrationConnection.handleConnection)); LocationThreadObj.IsBackground = true; LocationThreadObj.Start(); } catch (Exception e) { EventLog.WriteEntry("Safemobile", "Ex in appserver:Registration thread: " + e.ToString(), EventLogEntryType.Error, 23456); //Form1.appDead = true; } Thread.Sleep(1); } //myListener.Stop(); } } }