Esempio n. 1
0
        /// <summary>
        /// This will create a client socket and connect to a remote server socket which is prepared from the 
        /// connect initiator
        /// </summary>
        /// <param name="targetAddress"></param>
        public PeerSocket(ResponseHandlersCollection handlers, string _parentId, string _peerId, string remoteHost, int remotePort)
        {
            responseHandlers = handlers;

            parentId = _parentId;
            peerId = _peerId;

            clientSocket = new NetClient(parentId+"."+ peerId+".Client");
            clientSocket.OnReceived += new NetReceivedEventHandler<byte[]>(onClientReceiveData);
            clientSocket.TryConnect(remoteHost, remotePort);
        }
Esempio n. 2
0
        /// <summary>
        /// This will create a server socket on a random port, used to initiate a connection
        /// we send address of this server to the remote server to connect using a client socket
        /// The only exception is gateway socket that has no peerId (is null)
        /// </summary>
        /// <param name="_parentId"></param>
        /// <param name="_peerId"></param>
        public PeerSocket(ResponseHandlersCollection handlers, string _parentId, string _peerId)
        {
            responseHandlers = handlers;

            parentId = _parentId;
            peerId = _peerId;

            string myName = "";

            if (peerId == null)
            {
                myName = _parentId + ".Gateway";
            }
            else
            {
                myName = parentId + "." + peerId + ".Server";
            }

            serverSocket = new NetServer(myName);
            serverSocket.OnReceived += new NetClientReceivedEventHandler<byte[]>(onServerReceiveData);
            serverSocket.Start(IPAddress.Parse(defaultHost), random.Next(1025, 65500));
        }