当前位置:网站首页>Clients accessing the daytime service (TCP)
Clients accessing the daytime service (TCP)
2022-06-30 04:06:00 【Cod_ ing】
For the first time to use “winsock.in” May cause some functions to be unavailable , Solutions refer to Blog
/*TCPdaytime*/
#include<cstdlib>
#include<cstdio>
#include<winsock.h>
#include<string>
using namespace std;
void TCPdaytime(const char*,const char*);
void errexit(const char*,...);
SOCKET connectTCP(const char*, const char*);
#define LINELEN 128
#define WSVERS MAKEWORD(2,0)
/* main - TCP client for DAYTIME serive */
int main(int argc, char* argv[])
{
string host = "localhost"; // The client and server are on the same host
string service = "daytime"; // Standard service name
WSADATA wsadata;
switch (argc)
{
case 1:
host = "localhost";
break;
case 3:
service = argv[2];
/* FALL THROUGH */
case 2:
host = argv[1];
break;
default:
fprintf(stderr, "usage:TCPdaytime [host [port]]\n");
exit(1);
}
if (WSAStartup(WSVERS, &wsadata) != 0) //Win To establish a socket in the environment, you must first call
//errexit("WSAStartup failed\n");
TCPdaytime(host.c_str(), service.c_str()); // Completion time request service
WSACleanup();
return 0;
}
/* TCPdaytime - invoke Daytime on specified host and print results */
void TCPdaytime(const char* host, const char* service)
{
char buf[LINELEN + 1]; //buffer for one line of text
SOCKET s; //socket descriptor
int cc; //recv character count
s = connectTCP(host, service); // establish TCP Socket and connect to the server
cc = recv(s, buf, LINELEN, 0); // Complete data acceptance
while (cc != SOCKET_ERROR and cc > 0)
{
buf[cc] = '\0';
(void)fputs(buf, stdout);
cc = recv(s, buf, LINELEN, 0);
}
closesocket(s);
}
Reference resources MOOC Take the computer network open class of Harbin Institute of technology
边栏推荐
- .NET 7 的 JWT 配置太方便了!
- Huawei cloud native - data development and datafactory
- How to analyze and solve the problem of easycvr kernel port error through process startup?
- A minimalist way to integrate databinding into activity/fragment
- [cloud native] AI cloud development platform - Introduction to AI model foundry (developers can experience AI training model for free)
- Errno and PERROR
- 【论文阅读|深读】Role2Vec:Role-Based Graph Embeddings
- 华为云原生——数据开发与DataFactory
- Everyone, Flink 1.13.6, mysql-cdc2.2.0, the datetime (6) class extracted
- [Thesis reading | deep reading] dane:deep attributed network embedding
猜你喜欢

Simple theoretical derivation of SVM (notes)

Green new power and "zero" burden of computing power -- JASMINER X4 series is popular
![[Thesis reading | deep reading] role2vec:role based graph embeddings](/img/69/c94700fbbbda20df4e54803c703b48.png)
[Thesis reading | deep reading] role2vec:role based graph embeddings

lego_loam 代码阅读与总结

接口测试--如何分析一个接口?

Day 12 advanced programming techniques

技术分享| 融合调度中的广播功能设计

Interface testing -- how to analyze an interface?

如何利用FME 创建自己的功能软件

El upload Upload file (Manual upload, Automatic upload, upload progress)
随机推荐
Unity 在編輯器中輸入字符串時,轉義字符的輸入
[punch in - Blue Bridge Cup] day 4--------- split ('') cannot be used. There is a space after the last number of test cases. Split ()
Green new power and "zero" burden of computing power -- JASMINER X4 series is popular
The school training needs to make a registration page. It needs to open the database and save the contents entered on the registration page into the database
How to use Jersey to get the complete rest request body- How to get full REST request body using Jersey?
将DataBinding整合到Activity/Fragment的一种极简方式
Error in conditional filter (if) syntax in sum function in SQL Server2005
Ananagrams(UVA156)
DO280私有仓库持久存储与章节实验
Geometric objects in shapely
第十一天 脚本与游戏AI
.NET 7 的 JWT 配置太方便了!
The new paradigm of AI landing is "hidden" in the next major upgrade of software infrastructure
Jour 9 Gestion des scripts et des ressources
Solutions for project paths
节点CODE相同会导致数据重复
DBT product initial experience
Node-RED系列(二八):基于OPC UA节点与西门子PLC进行通讯
I spent three years in a big factory outsourcing, which subverted my understanding!
【论文阅读|深读】DANE:Deep Attributed Network Embedding