ConnectToServer() public static method

This code is used to connect to a TCP socket with timeout option.
Throws SocketException if can not connect. /// Throws TimeoutException if can not connect within specified timeoutMs ///
public static ConnectToServer ( EndPoint endPoint, int timeoutMs ) : Socket
endPoint System.Net.EndPoint IP endpoint of remote server
timeoutMs int Timeout to wait until connect
return Socket
Example #1
0
 /// <summary>
 /// Creates a communication channel using ServerIpAddress and ServerPort.
 /// </summary>
 /// <returns>Ready communication channel to communicate</returns>
 protected override ICommunicationChannel CreateCommunicationChannel()
 {
     return(new TcpCommunicationChannel(
                TcpHelper.ConnectToServer(
                    new IPEndPoint(IPAddress.Parse(_serverEndPoint.IpAddress), _serverEndPoint.TcpPort),
                    ConnectTimeout
                    )));
 }
Example #2
0
        /// <summary>
        /// Creates a communication channel using ServerIpAddress and ServerPort.
        /// </summary>
        /// <returns>Ready communication channel to communicate</returns>
        protected override ICommunicationChannel CreateCommunicationChannel()
        {
            Socket socket;

            if (_existingSocketInformation.HasValue)
            {
                socket = new Socket(_existingSocketInformation.Value);
                _existingSocketInformation = null;
            }
            else
            {
                socket = TcpHelper.ConnectToServer(new IPEndPoint(_serverEndPoint.IpAddress, _serverEndPoint.TcpPort), ConnectTimeout);
            }

            return(new TcpCommunicationChannel(socket));
        }