Analysis of socket programming in C # (6) Author: Wang Kaiming www.ASPCool.com Time: 2002-4-10 21:28:16
Through some of the above functions, the client program can be free to chat, and each user can also send a private message to each other. So the program has implemented the basic function of the chat room, but the last user must use the QuitChat () function. The specific implementation of this function is as follows: private void quitchat () {if (connection) {string command = "gone |" clientname; byte [] outbytes = system.text.encoding.ascii.getbytes (command.tochararray () NS.Write (Outbytes, 0, Outbytes.Length); ClientSocket.close ();} catch (exception) {}}} logwriter.close (); if (Receive! = Null& receive.isalive) Receive.abort (); this.text = "Client";} From this, the main part of the client program has been introduced. There are also some message processing functions of the button control, see the source code. At the same time, there is a chat recording function in the program, which is similar to the record function of the currently popular chat software. However, it is limited to the space, and it will be introduced here. Interested readers can study the source code behind this article. In this way, the client program is completed. The program run is shown below: Summary: This article initially introduces the basic concepts of the socket and the basic principle of the socket programming, and also showers to everyone through a good example. Implement methods and some programming skills. From it, we are not difficult to find that there is many superior programs that use C # to make socket programming and even network programming. The idea of the instance program is clear and easy to understand is a quite good example. I hope that you can study well. At the same time, I hope that everyone can further improve the program, making it more powerful, and more friendly interface. Finally, it is to indicate that this example program is compiled in VS.NET, and it may be different if you are still a beta version. Download code: http://www.aspcool.com/download/display.asp?did=330