14 using System.Collections.Generic;
15 using System.Configuration;
16 using System.Net.Sockets;
17 using System.Threading;
54 private static readonly
string BBconection = ConfigurationManager.ConnectionStrings[
"BB_Sensor_CONNECTION"].ConnectionString;
60 private static ManualResetEvent
_connected =
new ManualResetEvent(
false);
73 private static void Main(
string[] args)
76 Console.Title =
"BBPresenceSensor";
120 #region AcceptCallback 148 catch (SocketException)
161 #endregion AcceptCallback 163 #region ReceiveCallback 184 bytesRead = client.Socket.EndReceive(ar);
186 catch (SocketException)
204 client.BuildIncomingMessage(bytesRead);
207 client.PrintMessage();
210 client.ClearIncomingMessage();
216 client.Socket.BeginReceive(client.Buffer, 0, client.BufferSize, SocketFlags.None,
new AsyncCallback(
ReceiveCallback), client);
218 catch (SocketException)
229 #endregion ReceiveCallback 249 err =
"Async result null";
266 #endregion CheckState 287 Console.WriteLine(sensor);
291 #endregion CloseClient 293 #region CloseAllSockets 310 #endregion CloseAllSockets
static Socket CreateListener()
Create the connection needed for the TCP connection
static void SensorPStatus(bool Status)
static void SaveErrorData(string error)
Log all the error that occurs in the program
static void Main(string[] args)
static void ReceiveCallback(IAsyncResult ar)
Handler for received messages
static void CloseClient(BBSensorObjects client)
Closes a client socket and removes it from the client list
static readonly string BBconection
void Close()
Closes the connection
static void StartListening()
Listen for client connections
static void parseConnectionData(string connection)
Parse connection data
static Socket _sensorServer
static List< BBSensorObjects > _sensors
static ManualResetEvent _connected
static void AcceptCallback(IAsyncResult ar)
Handler for new connections
static bool CheckState(IAsyncResult ar, out string err, out BBSensorObjects client)
Checks IAsyncResult for null value
static void CloseAllSockets()
Closes all client and server connections