コード例 #1
0
        public ServerForm()
        {
            IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
            foreach (var ip in localIPs)
            {
                if (ip.ToString().IndexOf('.') > 0)
                {
                    Variable.IP = ip.ToString();
                }
            }

            //Variable.IP = "127.0.0.1";

            InitializeComponent();

            this.Text = "Trọng tài chính: " + Variable.IP + ":" + Variable.PORT;

            tcpServers = new TcpServers(this);
            Variable.SERVERSERVICES = new List<ServerService>();
            Variable.THREADS = new List<Thread>();

            // Add Event to handle when a client is connected
            Changed += new ChangedEventHandler(tcpServers.ClientAdded);

            tcpServers.StartServer();
            //tmrServer.Enabled = true;
        }
コード例 #2
0
        /// <summary>
        /// Constructor which accepts Client TCP object
        /// </summary>
        /// <param name="tcpClient"></param>
        public ServerService(ServerForm parent, TcpClient tcpClient)
        {
            this.owner = parent;
            tcpServers = new TcpServers(this.owner);
            // Get Stream Object
            connectedClient = tcpClient;
            clientStream = tcpClient.GetStream();

            // Create the state object.
            StateObject state = new StateObject();
            state.workSocket = connectedClient.Client;

            //Call Asynchronous Receive Function
            connectedClient.Client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                    new AsyncCallback(OnReceive), state);

            //connectedClient.Client.BeginDisconnect(true, new AsyncCallback(DisconnectCallback), state);
        }