Analysis of the socket programming in C # (5)

xiaoxiao2021-03-06  41

Analysis of socket programming in C # (5) Author: Wang Kaiming www.ASPCool.com Time: 2002-4-10 21:24:07 Views: 4688

After that, of course, it is the chat between the user, and is done by the receiveChat () function. This function is a stand-alone thread that handles messages sent by all users and users. It mainly processes commands such as Chat, Priv, Join, Gone, Quit, and how to process the method, and server side.

The specific function is implemented as follows: private void receiveChat () {bool keEpalive = true; while (keepalive) {path {byte [] buffer = new byte [2048]; ns.read (buffer, 0, buffer.length); string chatter = System.Text.Encoding.ascii.getstring (buffer); string [] tokens = chatter.split (new char [] {'|'}); if (tokens [0] == "chat") {r rtin.AppendText Tokens [1]); if (logging) Logwriter.writeline (tokens [1]);} f (tokens [0] == "priv") {RTBChatin.AppendText ("Private from"); RTBChatin.AppendText (TOKENS [ 1] .trim ()); RTBChatin.AppendText (tokens [2] "/ r / n"); if (logging) {Logwriter.write ("Private from"); Logwriter.write (Tokens [1] .trim ()); Logwriter.writeline (tokens [2] "/ r / n");}}} f (tokens [0] == "join") {r rs [1] .trim ()); RTBCHA Tin.AppendText ("HAS JOINED THE CHAT / R / N"); if (logging) {logwriter.writeline (tokens [1] "HAS Joined the chat");} String newguy = tokens [1] .trim (New Char [] {'/ r', '/ n'}); lbChatters.Items.add (newguy);} if (tokens [0] == "gone") {r rs [1] .trim (TOKENS [1] .trim) ))); RTBChatin.AppendText ("HAS LEFT THE CHAT / R / N"); if (logging) {logwriter.writeline (tokens [1] "HAS LEFT THE");

转载请注明原文地址:https://www.9cbs.com/read-72641.html

New Post(0)