In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces what is the Socket network communication class in C #, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let's take a look at it.
Abstract
The reason for the encapsulation of Socket socket communication library is that it is relatively complex to use sockets directly for network communication programming, especially for beginners. In fact, Microsoft has provided advanced wrapper classes for TCP and UDP communications since .net 2.0 as follows:
TcpListenerTcpClientUdpClient
Microsoft has been providing asynchronous communication interfaces based on Task tasks since. Net 4.0. The direct use of socket packaging library, many of the details of socket itself can not be controlled by themselves, this article is to provide a socket encapsulation for reference. The TCP communication library is partially encapsulated in this article, and UDP encapsulation can also be used by analogy:
CusTcpListenerCusTcpClient Code using System;using System.Text;using System.Net.Sockets;using System.Net Namespace NetDemo {/ / the class public class InternetProHelper {/ / related to network operations checks whether the set port number is correct and returns the correct port number. Invalid port number returns-1 public static int GetNetPort (string NetPort) {/ / declares the correct port number int resPort =-1 / / detect port number try {/ / if the port number passed in is empty, an exception if (NetPort = = "") {throw new Exception ("port number cannot be empty!") is thrown. ;} / / detect port range if ((Convert.ToInt32 (NetPort))
< ushort.MinValue) || (Convert.ToInt32(NetPort) >Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.