public void SendMsg() { if (string.IsNullOrEmpty(SendMsgInputField.text)) { return; } SocketServerBase.MultiSendMessage(SocketServerBase.Clients, SendMsgInputField.text); }
static void Main(string[] args) { SocketServerBase server = new SocketServerBase(); server.ReadCompleted += Server_ReadCompleted; server.Start(); Console.WriteLine("enter any key to exit."); Console.ReadKey(); }
public void StopSocket() { if (!started) { LogString = "Socket Stopped"; return; } SocketServerBase.StopSocketServer(); started = false; LogString = "Socket Stop"; }
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"; }
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; } }
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); } }
public void SendMsg(string msg) { SocketServerBase.MultiSendMessage(SocketServerBase.Clients, msg); }
public void Stop() { SocketServerBase.MultiSendMessage(SocketServerBase.Clients, "hahaha"); }
public void StartUnet() { SocketServerBase.StartSocketServer(9695); started = true; }