Use C # To write the socket program-Summary

Source: Internet
Author: User
Write a C # socket in the past two days. Program , Completed successfully. Here is a summary:
Function requirements: (1) when each client logs on, it can obtain other clients that are online, send messages to other clients (one or more), and send messages to the server.
(2) The server maintains all online clients and can send "system messages" to the clients ".
I use connection-oriented TCP/IP to achieve reliable data transmission! The key here is how to maintain the working sockets of each TCP connection on the server side! Because a client sends messages (data) to its corresponding working socket and receives messages (data) from it )! I use a hashtable to store the CUSTOMER NAME AND ITS WORKING socket.
Next, we should design how to send/receive data from the client/server! My design is to use a custom message format:
Message format and its meaning: 0 | login | who is online
0 | logout | who is offline
0 | online | count3 | someone1 | someone2 | all online users of someone3
1 | MSG system message
2 | tomembercount3 | someone1 | someone2 | someone3 | who sends messages to N online members. When n is the maximum value of all other members, the messages are sent to all members of the same group.
2 | MSG | who sends messages to the System
Based on the above requirements and design, I quickly wrote C # To the corresponding program implementation.

well, I guess this design can only be used as an experiment. As for the efficient commercial use, we have to make great efforts! Well, continue to work!
Appendix:
reference http://files.cnblogs.com/fuhongwei041/socket.doc

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.