Selecting a person to chat with in C# -
Consider the case of a LAN Messenger where many people are online I have to choose a special person to chat. How should I go about doing this in C #? What do I want to do is select a particular person by clicking on his name. After that whatever I type, it should be sent only in the case of IP LaMansager software (hopefully people use it). Someone can help me. Thank you
If you want to keep track of users, then I recommend a server application coding to all connections Here is a quick example (note that this is not a complete example):
Using the system. Colllections.Generic; Using System.Net; Using System.Net.Sockets; Using System.Text; Using System.Threading; Private TcpListener tcpListener; Private thread listener thread; Hear volatile hair; // Create client structure / class to manage connection information and names Private list & lt; Client & gt; Customers; // Constructor customers = new list & lt; Client & gt; (); TcpListener = New TcpListener (IP address no, 3000); Listen = true; ListenerThread = New Thread (New Thunderstart (ListenForClients)); ListenerThread.Start (); / / Sunoforclines Private Zero Shooforsions () {// Start the TCP Listener This.tcpListener.Start (); TcpClient tcpClient; While {listen} {try to suspend while looping until the client connects to tcpClient = this.tcpListener.AcceptTcpClient (); // Create a thread to handle communication with the client Thread ClientTrade = New Thread (New ParameteratedTextstart (Handle Message)); ClientThread.Start (tcpClient); } Hold {// handle errors}}} // handle messages (connect? Disconnect? You can customize!) Private Zero handel message (object client) {// Retrieve our client and network stream TCP client TCP Client = Start (Client Client) Client; NetworkStream Client stream = TCP client. Gatestream (); // Create our data byte [byte message = new byte [4096]; Int bytes read; String message; String [] data; // Set our encoder ASCIIEncoding encoder = new ASCIIEncoding (); While (true) {// clients retrieve message bytes = 0; Try {BitSerad = Client Stream. Read (Byte Message, 0, 4096); } Hold {break; } // Client was disconnected (bytes read == 0) break; // Decoding client message messages = encoder. Getstring (byte message, 0, bytes read); // handle the message ...}} Now again note that this is not a complete example and I know that I went everything over it but I hope that This will give you an idea. The message message may be a part of the message in the handle message function, if they are connected to chat servers / disconnecting, and other parameters you want to specify. This is a code taken from an application written to my father's company, so that I wrote the rights to each other's authority written to the CRM. If you have any further questions, please comment.
Comments
Post a Comment