Analysis of socket programming in C # (1) Author: Wang Kaiming www.ASPCool.com Time: 2002-4-10 21:16:32 Views: 6045
C # is Microsoft's new language with VS.NET. It as a emerging language, has a strong C , and has a VB, etc. RAD characteristics. Moreover, Microsoft launched C # main purposes to fight Sun's Java. Everyone knows the powerful features of the Java language, especially in network programming. So, C # is naturally not willing to return in terms of network programming. This article introduces you to some basic knowledge of the Sockets programming, in order to make it a general understanding of this. First of all, I introduce you to the concept of socket. Sockets Basic Concept: Socket is the cornerstone of communication, is a basic operating unit that supports network communication of TCP / IP protocol. The socket can be seen as an endpoint between the two-way communication between the different hosts, which constitutes a single host and the programming interface between the entire network. Sockets are present in the communication domain, and the communication domain is an abstract concept introduced by the general thread through socket communication. Sockets are usually exchanged with sockets in the same domain (data exchange may also pass the boundaries of the domain, but you must perform some explanation). Various processes use this same domain to communicate with Internet protocol clusters. Sockets can be classified according to communication nature, which is visible to the user. Applications generally communicate only between the same class. However, as long as the underlying communication protocol allows, different types of sockets can also be communicated. There are two different types of sockets: flow sleeves and data sets. Socket works: To communicate through the Internet, you need at least one pair of sockets, one of which is running on the client, we calls CLIENTSOCKET, the other runs on the server, we call Serversocket. Depending on the connection start, the connection between the socket can be divided into three steps: server listening, client request, connection confirmation. The so-called server monitoring is that the server end sleeve is not locked in the specific client sleeve, but is in a state in which the connection is connected, and the network status is monitored in real time. The so-called client request refers to a connection request by the client's socket, and the target to be connected is the server side's socket. To this end, the client's socket must first describe the socket of the server it want to connect, pointing to the address and port number of the server end sleeve, and then the connection request is proposed to the server end sleeve. The so-called connection confirmation means that when the server-side socket monitor is listened or received a connection request to the client sleeve, it responds to the request of the client sleeve, build a new thread and connect the server end. The description sent to the client, once the client confirms this description, the connection is established. The server end sleeve continues to be listened, and continues to receive connection requests for other client-side sockets. Socket programming instances in C #: By simply introducing the basic concepts of the socket and the basic principles of socket programming, I think everyone has a preliminary understanding of the socket programming. However, the above introduction is only basic concepts and principles, and it is necessary to actually need a certain job. The best way to true understanding of basic concepts and principles is to do an instance yourself. Below you, I will introduce you to an instance of a good-to-write programming program-chat room program. This program is based on the C / S (Server / Client) architecture, the program contains a server-side application and a client application. First, run the server on the server, and the program starts the server to listen. Then, you can open the client's application on the client.