当前位置:网站首页>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
边栏推荐
猜你喜欢

Error encountered in SQL statement, solve

Do280 private warehouse persistent storage and chapter experiment

(03). Net Maui actual combat basic control
![[note] May 23, 2022 MySQL](/img/a1/dd71610236729e1d25c4c3e903c0e0.png)
[note] May 23, 2022 MySQL

About manipulator on Intelligent Vision Group

《机器人SLAM导航核心技术与实战》第1季:第0章_SLAM发展综述

lego_ Reading and summary of loam code

【图像融合】基于交叉双边滤波器和加权平均实现多焦点和多光谱图像融合附matlab代码

I spent three years in a big factory outsourcing, which subverted my understanding!

Huawei cloud native - data development and datafactory
随机推荐
MySQL updates JSON string in array form
第九天 脚本与资源管理
[operation] getting started with MySQL on May 23, 2022
接口测试--如何分析一个接口?
《机器人SLAM导航核心技术与实战》第1季:第0章_SLAM发展综述
尝试链接数据库时出现链接超时报错,如何解决?
Do280 private warehouse persistent storage and chapter experiment
[cloud native] AI cloud development platform - Introduction to AI model foundry (developers can experience AI training model for free)
[note] May 23, 2022 MySQL
You know AI, database and computer system
【模糊神经网络预测】基于模糊神经网络实现水质预测含Matlab源码
Everyone, Flink 1.13.6, mysql-cdc2.2.0, the datetime (6) class extracted
Interface test tool postman
Day 9 script and resource management
Wang Shuang - assembly language learning summary
I get n offers in two months. I don't have any difficult interviewers here
Node red series (28): communication with Siemens PLC based on OPC UA node
Semantic segmentation resources
Solutions for project paths
AI落地的新范式,就“藏”在下一场软件基础设施的重大升级里