private void btnListen_Click(object sender, EventArgs e) { IPAddress ipAddr = IPAddress.Parse(txtIp.Text); ChatServer mainServer = new ChatServer(ipAddr); ChatServer.StatusChanged += new StatusChangedEventHandler(mainServer_StatusChanged); mainServer.StartListening(); txtLog.AppendText("Monitoring for connections...\r\n"); }
public static void Main(string[] args) { var server = new ChatServer(); server.OnGotChat += (o, e) => Console.WriteLine($"{e.UserId} sends message to {e.DestinationUserId} {e.ChatContent}"); server.OnGotLogOn += (o, e) => Console.WriteLine($"{e.UserId} log on!"); server.OnGotHeartBeat += (o, e) => Console.WriteLine($"{e.UserId} got heartbeat!"); server.Start(); }
public Window1() { CheckInstance(); InitializeComponent(); if (System.Configuration.ConfigurationManager.AppSettings["LogUserMessages"] == "true") { logUserMessagesMenuItem.IsChecked = true; } else { logUserMessagesMenuItem.IsChecked = false; } mainServer = new ChatServer(); txtIp.Text = mainServer.getSelfIpAddress(); ChatServer.StatusChanged += new StatusChangedEventHandler(mainServer_StatusChanged); }
static void Main(string[] args) { string message; Server = new ChatServer(591); Server.PacketRecieved += ProcessPacket; Server.Start(); Console.WriteLine("--------------Server started--------------"); while (true) { message = Console.ReadLine(); Server.SendPacket(new MessagePacket(new User("Server"), message)); } }
public MainWindow() { InitializeComponent(); lbActiveClients.SelectionChanged += (_s, _e) => { if (lbActiveClients.SelectedValue == null) { return; } if (lbActiveClients.SelectedValue is Client) { tbTargetUsername.Text = (lbActiveClients.SelectedValue as Client).Username; } }; this.DataContext = cs = new ChatServer(); }
private void RunChat() { //try //{ var line = string.Empty; while (true) { line = Reader.ReadLine(); ChatServer.BroadcastMessage(ChatClient.Id, line); if (line == null) { break; } } //} //catch (Exception exception) //{ // Console.WriteLine(exception); //} }
private void cbStartStop_Checked(object sender, RoutedEventArgs e) { if (cbStartStop.IsChecked == true) { try { var port = Int32.Parse(tbPortNumber.Text); server = new ChatServer(port, cbInterfaces.SelectedItem, tbServerName.Text); server.ClientConnected += ServerOnClientConnected; server.ClientDisconnected += ServerOnClientDisconnected; server.JournalAdd += ServerOnJournalAdd; var serverName = tbServerName.Text; if (string.IsNullOrWhiteSpace(serverName)) { ServerOnJournalAdd("Введите корректный номер порта или имя сервера", null); } else { server.StartServer(); SetControls(false); } } catch (Exception ex) { ServerOnJournalAdd("Введите корректный номер порта или имя сервера", new ErrorEventArgs(ex)); } } else { if (server == null) { return; } server.StopServer(); SetControls(true); } }
static void Main(string[] args) { _handler += Handler; SetConsoleCtrlHandler(_handler, true); AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper; TalkyLog.Debug("Server|Starting|"); Console.Write("Starting server... "); int port = 0; if (args.Length > 0) { string thePort = args[0]; int.TryParse(thePort, out port); } if (port <= 0) { port = 4096; } Console.WriteLine($" on port {port}"); _chatServer1 = new ChatServer(port); WaitForAnotherInstance(); ManageInstances(); _chatServer1.Init(); try { (new Thread(_chatServer1.Start)).Start(); } catch (System.Exception ex) { Console.Write($"Server start error : {ex}"); } }
private void cbStartStop_Checked(object sender, RoutedEventArgs e) { if (cbStartStop.IsChecked == true) { // validate the port number try { var port = Int32.Parse(tbPortNumber.Text); server = new ChatServer(port, cbInterfaces.SelectedItem, tbServerName.Text); server.ClientConnected += ServerOnClientConnected; server.ClientDisconnected += ServerOnClientDisconnected; var serverName = tbServerName.Text; if (string.IsNullOrWhiteSpace(serverName)) { ShowError(); } else { server.StartServer(); SetControls(false); } } catch { ShowError(); } } else { if (server == null) { return; } server.StopServer(); SetControls(true); } }
static void Main(string[] args) { Parser.Default.ParseArguments <Options>(args).WithParsed(options => { var srv = new ChatServer(options.IPAddress, options.Port, options.MaxClients); srv.Start(); // Windows closed or user types quit AppDomain.CurrentDomain.ProcessExit += (sender, args) => srv.Stop(); // Ctrl + C or Ctrl + Break Console.CancelKeyPress += new ConsoleCancelEventHandler((sender, args) => srv.Stop()); // Wait until the quit command is executed Console.WriteLine($"Server is now listening on {options.IPAddress}:{options.Port}"); Console.WriteLine("Type 'quit' or press Ctrl^C to stop the server"); while (Console.ReadLine() != "quit") { Task.Delay(100).Wait(); } }); }
//@dany modifiche private void MainForm_Load(object sender, EventArgs e) { // Create a new instance of the ChatServer object mainServer = new ChatServer(this);//alby4 //startListeningToolStripMenuItem.Text = "Start listening"; btnSend.Enabled = false; txtMessage.Enabled = false; this.FormClosing += new FormClosingEventHandler(Form1_Closing); this.txtLog.ForeColor = System.Drawing.Color.Green; this.txtLog.Font = new Font(txtLog.SelectionFont, FontStyle.Italic); this.txtLog.Text = "To use the program you have to let clients connect to you.\r\nSelect File -> Connect, fill in the fields and click ok.\r\nOnce connected you can share your desktop through File -> Start Recording, if you want to change what to share, go to Options -> Recording Options\r\n\r\n"; //alby label1.Size = new System.Drawing.Size(15, 17); dis(); label1.Font = new System.Drawing.Font("Tahoma", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); //alby end }
public MainWindow() { InitializeComponent(); cs = new ChatServer(); this.DataContext = cs; }
private void AcceptClient() { srReceiver = new System.IO.BinaryReader(tcpClient.GetStream()); swSender = new System.IO.BinaryWriter(tcpClient.GetStream()); byte[] answer; byte[] response; Int32 length; // lese laenge von pub key von client length = srReceiver.ReadInt32(); // empfange client pub key response = new byte[length]; response = srReceiver.ReadBytes(length); string clientPubKey = Converter.fromByteArrayToString(response); Encryption clientEncryption = new Encryption(clientPubKey); // sende mit client pub key verschlüsselt rij key + iv answer = clientEncryption.EncryptRSA(serverEncryption.getRijKey()); sendMessage(answer); answer = clientEncryption.EncryptRSA(serverEncryption.getRijIV()); sendMessage(answer); // empfange chatmessage objekt mit usernamen signature und message length = srReceiver.ReadInt32(); response = new byte[length]; response = srReceiver.ReadBytes(length); Chatmessage message = (Chatmessage)Converter.fromByteArrayToObject(serverEncryption.DecryptRijndael(response)); int pos = 0; if (message.Signature != _acceptedSignature) { pos = -1; } currUser = message.Transmitter; if (currUser != "") { Chatmessage serverResponse = new Chatmessage(); serverResponse.Transmitter = "Administrator"; serverResponse.Receiver = currUser; if (pos == -1) { serverResponse.Message = "0|Wrong Client."; byte[] msg = serverEncryption.EncryptRijndael(Converter.fromObjectToByteArray(serverResponse)); sendMessage(msg); CloseConnection(); return; } else if (ChatServer.userInfos.ContainsKey(currUser) == true) { serverResponse.Message = "0|This username already exists."; byte[] msg = serverEncryption.EncryptRijndael(Converter.fromObjectToByteArray(serverResponse)); sendMessage(msg); CloseConnection(); return; } else if (currUser == "Administrator") { serverResponse.Message = "0|This username is reserved."; byte[] msg = serverEncryption.EncryptRijndael(Converter.fromObjectToByteArray(serverResponse)); sendMessage(msg); CloseConnection(); return; } else { serverResponse.Message = "1|Connected Successfully"; byte[] msg = serverEncryption.EncryptRijndael(Converter.fromObjectToByteArray(serverResponse)); sendMessage(msg); // send actual user list MemoryStream stream = new MemoryStream(); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(stream, ChatServer.users); msg = stream.ToArray(); sendMessage(msg); // add new user ChatServer.AddUser(tcpClient, currUser, serverEncryption, message.OperatingSystem); } } else { CloseConnection(); return; } try { while ((length = Convert.ToInt32(srReceiver.ReadInt32())) != 0) { response = new byte[length]; response = srReceiver.ReadBytes(length); var rawResponse = Converter.fromByteArrayToObject(serverEncryption.DecryptRijndael(response)); Chatmessage chatResponse = (Chatmessage)rawResponse; switch (chatResponse.MessageType) { case Chatmessage.MESSAGE_TYPE_DISCONNECT: // client wants do disconnect ChatServer.RemoveUser(currUser); break; case Chatmessage.MESSAGE_TYPE_USER_INFO: // send user info of a user to client ChatServer.SendMessage(currUser, chatResponse.Message, chatResponse.Receiver, Chatmessage.MESSAGE_TYPE_USER_INFO); break; case Chatmessage.MESSAGE_TYPE_MESSAGE: default: // normal chat message or default behaviour if (chatResponse.Message.Length > 0) { ChatServer.SendMessage(currUser, chatResponse.Message, chatResponse.Receiver, Chatmessage.MESSAGE_TYPE_MESSAGE); } else { ChatServer.RemoveUser(currUser); } break; } } } catch { ChatServer.RemoveUser(currUser); } }
public static void Main(String[] args) { ChatServer chatServer = new ChatServer(); chatServer.run(); }