예제 #1
0
 public void SendMsg()
 {
     if (string.IsNullOrEmpty(SendMsgInputField.text))
     {
         return;
     }
     SocketServerBase.MultiSendMessage(SocketServerBase.Clients, SendMsgInputField.text);
 }
예제 #2
0
    static void Main(string[] args)
    {
        SocketServerBase server = new SocketServerBase();

        server.ReadCompleted += Server_ReadCompleted;
        server.Start();

        Console.WriteLine("enter any key to exit.");
        Console.ReadKey();
    }
예제 #3
0
    public void StopSocket()
    {
        if (!started)
        {
            LogString = "Socket Stopped";
            return;
        }

        SocketServerBase.StopSocketServer();
        started = false;

        LogString = "Socket Stop";
    }
예제 #4
0
    public void StartSocket()
    {
        if (started)
        {
            LogString = "Socket Started";
            return;
        }

        int port;

        int.TryParse(PortInputField.text, out port);
        SocketServerBase.StartSocketServer(port);
        started = true;

        LogString = "Socket Start";
    }
예제 #5
0
    public void SendData()
    {
        byte[] buffer = System.Text.Encoding.UTF8.GetBytes(SendInputField.text);
        int    size   = buffer.Length;

        if (size == 0)
        {
            return;
        }

        if (HostId == 100)
        {
            SocketServerBase.SendMessage(clientInfo.Split(':')[1], SendInputField.text);
        }
        else
        {
            NetworkTransport.Send(HostId, ConnectionId, ChannelId, buffer, size, out _error);
            _networkError = (NetworkError)_error;
        }
    }
예제 #6
0
        private void ButtonStartClick(object sender, EventArgs e)
        {
            try
            {
                Int32 localPort;
                if (!Int32.TryParse(txtLocalPort.Text, out localPort))
                {
                    throw new Exception("Local port number is wrong.");
                }
                _socketServer = cmbUseSSL.SelectedIndex == 0 ? (SocketServerBase)(chkAllNetwork.Checked ? new SocketServerSslAsync(IPAddress.Any, localPort) : new SocketServerSslAsync(txtLocalAddress.Text, localPort)) :
                                (SocketServerBase)(chkAllNetwork.Checked ? new SocketServerAsync(IPAddress.Any, localPort) : new SocketServerAsync(txtLocalAddress.Text, localPort));
                _socketServer.Context         = WindowsFormsSynchronizationContext.Current;
                _socketServer.Connected      += SocketClientConnected;
                _socketServer.Disconnected   += SocketClientDisconnected;
                _socketServer.SentData       += SocketClientSentData;
                _socketServer.ReceivedData   += SocketClientReceivedData;
                _socketServer.SocketError    += SocketClientSocketError;
                _socketServer.Error          += SocketClientError;
                _socketServer.SocketSecurity += SocketSecurityEventRaised;

                if (cmbUseSSL.SelectedIndex == 0)
                {
                    ((SocketServerSslAsync)_socketServer).SslProtocol = (SslProtocols)Enum.Parse(typeof(SslProtocols), cmbSSLProtocol.Text);
                    ((SocketServerSslAsync)_socketServer).CheckCertificateRevocation    = cmbCertificateRevocation.SelectedIndex == 0;
                    ((SocketServerSslAsync)_socketServer).CertificateValidationCallback = CertificateErrorsCallback;
                    ((SocketServerSslAsync)_socketServer).ServerCertificate             = String.IsNullOrEmpty(txtCertificatePassword.Text) ? new X509Certificate2(txtCertificateFile.Text) : new X509Certificate2(txtCertificateFile.Text, txtCertificatePassword.Text);
                }

                _socketServer.Start();
                EnableDisableButtonControls(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                EnableDisableButtonControls(true);
            }
        }
예제 #7
0
 public void SendMsg(string msg)
 {
     SocketServerBase.MultiSendMessage(SocketServerBase.Clients, msg);
 }
예제 #8
0
 public void Stop()
 {
     SocketServerBase.MultiSendMessage(SocketServerBase.Clients, "hahaha");
 }
예제 #9
0
 public void StartUnet()
 {
     SocketServerBase.StartSocketServer(9695);
     started = true;
 }