private static void RealStart(CloudPortsRow row) { int outputPort = row.getOutPort(); String nodeName = row.getNodeName(); InSocket inputSocket = new InSocket(row.getInPort(), nodeName); OutSocket outputSocket = new OutSocket(outputPort, nodeName); while (true) { inputSocket.ListenForConnection(); outputSocket.ListenForConnection(); SendingManager.addOutSocket(outputSocket); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Connected with node: " + nodeName); try { inputSocket.ListenForIncomingData(); } catch (SocketException e) { SendingManager.removeSocket(outputSocket); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Node " + nodeName + " disconnected."); } } }
private static void PrintSendInformation(OutSocket outputSocket, int destinationPort) { string timeStamp = CableCloud.GetTimeStamp(); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(timeStamp + " | Sent to node " + outputSocket.getNodeName() + " to port " + destinationPort.ToString() + Environment.NewLine); }
public static void Send(byte[] dataToSend, String sourceNode, int sourcePort) { lock (SyncObject) { int destinationPort = ConnectionsTable.getDestinationPort(sourceNode, sourcePort); byte[] preparedData = PrepareDataToSend(sourceNode, sourcePort, destinationPort, dataToSend); String destinationNodeName = ConnectionsTable.getDestinationNodeName(sourceNode, sourcePort); OutSocket outputSocket = getAssociatedSocket(destinationNodeName); outputSocket.Send(preparedData); PrintSendInformation(outputSocket, destinationPort); } }
private static OutSocket getAssociatedSocket(string destinationNodeName) { OutSocket socketToReturn = null; String nodeName = null; for (int i = 0; i < outSockets.Count; i++) { OutSocket outputSocket = outSockets.ElementAt(i); nodeName = outputSocket.getNodeName(); if (nodeName.Equals(destinationNodeName)) { socketToReturn = outputSocket; } } return(socketToReturn); }
private static void PrintSendInformation(OutSocket outputSocket, int destinationPort) { Console.WriteLine("Sent to node " + outputSocket.getNodeName() + "to port " + destinationPort.ToString()); }
public static void addOutSocket(OutSocket outSocket) { outSockets.Add(outSocket); }
public static void removeSocket(OutSocket outSocket) { outSockets.Remove(outSocket); }