private void createSockets()
        {
            FacetAccess facet_acess_server = this.Facet [ThisFacetInstance];

            foreach (KeyValuePair <int, FacetAccess> facet_access_client in this.Facet)
            {
                int facet_instance = facet_access_client.Key;
                if (facet_instance != this.ThisFacetInstance)
                {
                    string      ip_address_client = facet_access_client.Value.ip_address;
                    int         port_client       = facet_access_client.Value.port + this.ThisFacetInstance;
                    IPHostEntry ipHostInfo_client = Dns.GetHostEntry(ip_address_client);
                    IPAddress   ipAddress_client  = ipHostInfo_client.AddressList [0];
                    IPEndPoint  endPoint_client   = new IPEndPoint(ipAddress_client, port_client);
                    end_point_client [facet_instance] = endPoint_client;

                    Trace.WriteLineIf(this.TraceFlag == true, "CREATE SOCKETS - end_point_client[" + facet_instance + "]=" + endPoint_client);

                    string      ip_address_server = facet_acess_server.ip_address;
                    int         port_server       = facet_acess_server.port + facet_instance;
                    IPHostEntry ipHostInfo_server = Dns.GetHostEntry(ip_address_server);
                    IPAddress   ipAddress_server  = ipHostInfo_server.AddressList [0];
                    IPEndPoint  endPoint_server   = new IPEndPoint(ipAddress_server, port_server);
                    end_point_server [facet_instance] = endPoint_server;

                    Trace.WriteLineIf(this.TraceFlag == true, "CREATE SOCKETS - end_point_server[" + facet_instance + "]=" + endPoint_server);

                    // Create a TCP/IP client socket.
                    Socket client_socket = new Socket(AddressFamily.InterNetwork,
                                                      SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);

                    // Create a TCP/IP server socket.
                    Socket server_socket = new Socket(AddressFamily.InterNetwork,
                                                      SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);

                    server_socket.SendTimeout            = server_socket.ReceiveTimeout = client_socket.SendTimeout = client_socket.ReceiveTimeout = -1;
                    client_socket_facet [facet_instance] = client_socket;
                    server_socket_facet [facet_instance] = server_socket;
                }
            }

            Thread thread_connect_sockets = new Thread(new ThreadStart(connectSockets));
            Thread thread_accept_sockets  = new Thread(new ThreadStart(acceptSockets));

            thread_connect_sockets.Start();
            thread_accept_sockets.Start();

            Trace.WriteLineIf(this.TraceFlag == true, "CREATE_SOCKETS - connectSockets and acceptSockets launched !!!");

            thread_connect_sockets.Join();
            thread_accept_sockets.Join();

            Trace.WriteLineIf(this.TraceFlag == true, "CREATE_SOCKETS - connectSockets and acceptSockets finished !!!");
        }
Ejemplo n.º 2
0
 void configure_facet_address(IBindingKind unit_slice, string[] ip_address_facets, int[] port_facets)
 {
     foreach (KeyValuePair <int, int[]> facet in unit_slice.FacetIndexes)
     {
         foreach (int i in facet.Value)
         {
             FacetAccess facet_access = new FacetAccess(ip_address_facets [i], port_facets [i]);
             unit_slice.addFacetAccessInfo(i, facet_access);
             Console.WriteLine("ADDING FACET TO UNIT SLICE - fact=" + i + ", address = " + ip_address_facets [i] + ", port = " + port_facets [i]);
         }
     }
 }