Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize TCP and UDP Network programming by C++ Socket

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how C++ Socket implements TCP and UDP network programming. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Preface

Socket programming is divided into two modules: TCP and UDP, in which TCP is reliable and secure, and is often used to send files, while UDP is unreliable and insecure, and is often used for video calls.

As shown below:

Header files and libraries:

# include # pragma comment (lib, "ws2_32.lib")

Preparatory work:

After creating the project, first right-click the project and select properties

Then select CAccord Craft +-preprocessor-preprocessor definition

Add the string _ WINSOCK_DEPRECATED_NO_WARNINGS to it and click apply!

TCP

Connection process diagram:

Both the tcp server and client are created by following the steps in the figure above!

1)。 Server

Initialize socket library

Socket () in the corresponding figure

WORD wVersion;WSADATA wsaData;int err;// setting version, it can be understood as 1.1wVersion = MAKEWORD (1,1); / / example: MAKEWORD (a, b)-- > b | a b | a

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report