Tuesday, October 19, 2010

On the C # programming in the socket


C # is Microsoft's new with the VS.net a language. As a new language, with C + +, strong, and so they have a VB RAD features. Moreover, Microsoft introduced C # main purpose is to counter Sun's Java. We all know the power of Java language, especially in network programming. So, C # programming in the network are also far behind in human nature. In this paper, we introduce C # to be achieved Sockets (Sockets) some basic knowledge of programming in order to enable all of us have a general understanding of this. First, I introduce to you the concept of the socket.

Socket basic concepts:

Socket is the cornerstone of communication, support TCP / IP protocol the basic operation of the network communication unit. Socket can be seen as different host two-way communication process between the endpoints, which constitutes a single host within and between the network programming interface. Sockets exist in the communications field, communication field is to deal with the general thread through the socket communication and the introduction of an abstract concept. Sockets are usually the domain of the socket and the exchange of the same data (data exchange across domain boundaries may be, but then must perform an interpreter). Processes use the same domain with each other using Internet protocols to communicate cluster.

Sockets can communicate the nature of the classification of this nature is visible for the user. Applications generally only in the same class to communicate between sockets. But as long as the underlying communication protocol to allow different types of socket communication between the also still can. There are two different types of sockets: stream sockets and datagram sockets.

Socket works:

To communicate through the Internet, you need at least a pair of sockets, one of the runs on the client side, we call ClientSocket, another run on the server side, we call ServerSocket.

According to the way and start to connect the local socket to connect to target, the socket connection between the process can be divided into three steps: server monitoring, client requests, the connection confirmation.

The so-called server monitoring, server-side socket is not locate a specific client socket, but is waiting to connect the state, real-time monitoring network status.

The so-called client requests, is made by the client's socket connection requests, the goal is to connect to server-side socket. To this end, the client socket must first describe it to connect to the server socket, that socket server address and port number, and then made to the server-side socket connection requests.

The so-called link to confirm, when a server-side socket listening to or received by the client socket connection request, it will respond to the request of the client socket to create a new thread, the server-side socket description to the client, once the client to confirm this description, the connection is established better. The server-side socket in listening state to continue to receive other client socket connection requests.

Socket programming in C # Example:

Brief introduction to you through the basic concepts of socket programming and realization of the basic principles of the socket, I think we have a preliminary socket programming knowledge. However, the above described only the basic concepts and principles, to really use or need some work. On the basic concepts and principles of true understanding of the best way is to make yourself an example, here I introduce to you a very good realization of socket programming with C # examples - chat room program.

This procedure is based on C / S (server / client) architecture, the program includes a server-side application and a client application. First, the server is running server-side application, run the program started a server listening. Then, the client can open the client application. Program opened with the server-side applications can connect, that is, to client requests. In connection confirmation, the client user and other users in chat client. No limit on the number of clients, but also support the "whisper" chat mode, support chat. So this is a learning socket programming pretty good example. Moreover, the procedure in order to handle each client's information is also used multi-threading mechanism. In each client and server-side connection is successful, the establishment of a thread between them. This use of a multi-threaded, the client will not interaction between, even if one of them wrong and will not affect another.






Recommended links:



2.0 Homogenization



AVI to MKV



Specialist Audio Rippers And Converters



With the SET command to capture multi-line error



China OLPC ALLIANCE brewing threat of Wintel alliance formed



Wizard XML Or CSS Tools



how to solve the sql server Database query slow



ADSL FAQ wonderful Q & A?



Vigilance "wind Downloader" Summer lift vitality and



Describes the PROPERTIES of the problem MIDP



Blizzard: "StarCraft 2" continues to stand by the end of 2009 for SALE



YouTube to WMV



Matroska to MPEG



No comments:

Post a Comment