예제 #1
0
        private void ConnectToServer()
        {
            IPHostEntry ipHostInfo = Dns.GetHostEntry(host);
            IPAddress   ipAddress  = ipHostInfo.AddressList[0];
            IPEndPoint  ipEndPoint = new IPEndPoint(ipAddress, port);

            senderSema.Wait();
            sender = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            while (true)
            {
                try
                {
                    WriteLog(LogStrings.TryingToConnectToEndPoint(ipEndPoint));
                    sender.Connect(ipEndPoint);
                    WriteLog(LogStrings.ConnectedSuccessfullyToEndPoint(ipEndPoint));
                    senderSema.Release();
                    break;
                }
                catch (Exception exc)
                {
                    WriteLog(LogStrings.ExceptionWasThrown(exc));
                }
            }
        }