Exemple #1
0
        private async void Connect(IPAddress ip) // 이 작업 끝나기 전까지는 다른 작업 안함.
        {
            if (connection?.Connected ?? false)
            {
                var result = MessageBox.Show("Already connected. Reconnect?", "", MessageBoxButtons.YesNo);// 재 연결 하시겠습니까?
                if (result == DialogResult.No)
                {
                    return;
                }

                connection.Disconnect(false);
                connection.Close();
                connection = null;
            }
            //IPAddress ipAddress = IPAddress.Parse("221.143.21.37");
            IPEndPoint remoteEP = new IPEndPoint(ip, 52217);

            // Create a TCP/IP socket.
            try
            {
                Socket server = new Socket(ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

                await server.ConnectAsync(remoteEP);

                //richTextBox1.Text += $"Connected: {server.Connected} \n";

                connection = new SocketEx(server);

                await connection.SendMessageAsync(new CS_Login
                {
                    UserName = "******",
                });

                await HandleReceiveAsync();
            }
            catch (Exception ex)
            {
                richTextBox1.Text += "Error: " + ex.Message;
                connection?.Close();
                connection = null;
            }
        }
Exemple #2
0
        private async void Connect(IPAddress ip)
        {
            if (connection?.Connected ?? false)
            {
                var result = MessageBox.Show("Already connected. Reconnect?", "", MessageBoxButtons.YesNo);
                if (result == DialogResult.No)
                {
                    return;
                }
                connection.Disconnect(false);
                connection.Close();
                connection = null;
            }

            IPEndPoint remoteEP = new IPEndPoint(ip, 52217);

            // Create a TCP/IP socket.
            try
            {
                Socket server = new Socket(ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

                await server.ConnectAsync(remoteEP);

                connection = new SocketEx(server);

                await connection.SendMessageAsync(new CS_Login
                {
                    UserName = "******",
                });

                await HandleReceiveAsync();
            }
            catch (Exception ex)
            {
                ChattingListTextBox.Text += "Error: " + ex.Message;
                connection?.Close();
                connection = null;
            }
        }
        /// <summary>
        /// Connects to IMAP server.
        /// </summary>		
        /// <param name="host">Host name.</param>
        /// <param name="port">Port number. Default IMAP port is 143 and SSL port is 993.</param>
        /// <param name="ssl">Specifies if to connected via SSL.</param>
        public void Connect(string host,int port,bool ssl)
        {
            if(!m_Connected){
                m_pSocket = new SocketEx();
                m_pSocket.Connect(host,port,ssl);

                string reply = m_pSocket.ReadLine();
                reply = reply.Substring(reply.IndexOf(" ")).Trim(); // Remove Cmd tag

                if(!reply.ToUpper().StartsWith("OK")){
                    m_pSocket.Disconnect();
                    m_pSocket = null;
                    throw new Exception("Server returned:" + reply);
                }

                m_Connected = true;
                // Clear path separator, so next access will get it.
                m_PathSeparator  = '\0';
            }
        }