Example #1
0
        // public abstract void sendMessage(LoginData login/*, Message message*/);

        /// <summary>
        /// Is called from open connection
        /// </summary>
        /// <param name="remoteEP"></param>
        /// <param name="client"></param>
        protected static void Connect(EndPoint remoteEP, Socket client)
        {
            client.BeginConnect(remoteEP,
                                new AsyncCallback(ConnectCallback), client);

            ConnectDone.WaitOne();
        }
Example #2
0
        private bool CheckAllConnectionDone()
        {
            foreach (var block in mNetworkBlocks)
            {
                if (block.Value.State == MiraeNetworkState.None)
                {
                    return(false);
                }
            }

            foreach (var block in mNetworkBlocks)
            {
                if (block.Value.State == MiraeNetworkState.Connected)
                {
                    mReadyList.Add(block.Value);
                }
            }

            if (mStartConnect)
            {
                mStartConnect = false;
                ConnectDone.Invoke(mReadyList.Count > 0);
            }
            return(true);
        }
Example #3
0
        public void Start(ClientGUI form)
        {
            try
            {
                _remoteEP = new IPEndPoint(IPAddress.Parse(Ip), Port);
                _client   = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                State state = new State(1024, this);
                state.StateSocket = _client;
                state.StateForm   = form;
                ClientForm        = form;

                _client.BeginConnect(_remoteEP, new AsyncCallback(Helper.ConnectCallback), state);
                ConnectDone.WaitOne();
                if (_client.Connected)
                {
                    form.Show();
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #4
0
        public void Start()
        {
            try
            {
                _remoteEP = new IPEndPoint(IPAddress.Parse(Ip), Port);
                _client   = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                _client.BeginConnect(_remoteEP, new AsyncCallback(Helper.ConnectCallback), _client);
                ConnectDone.WaitOne();
            }
            catch (SocketException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #5
0
        /// <summary>
        /// Is called if client connects to server
        /// </summary>
        /// <param name="asyncResult">The result of the Conection</param>
        protected static void ConnectCallback(IAsyncResult asyncResult)
        {
            try
            {
                // Retrieve the socket from the state object.
                Socket client = (Socket)asyncResult.AsyncState;
                // Complete the connection.
                client.EndConnect(asyncResult);
                Trace.WriteLine("Socket connected to {0}", client.RemoteEndPoint.ToString());
                // Signal that the connection has been made.
                ConnectDone.Set();

                Send(client, "<?xml version='1.0'?>\n<stream:stream xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xmlns='jabber:client' to='" + Logins.ElementAt(Sockets.IndexOf(client)).getDomain() + "' xml:lang='de' xmlns:xml='http://www.w3.org/XML/1998/namespace'>");

                Receive(client);
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
            }
        }