当前位置:网站首页>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
边栏推荐
- Linear interpolation of spectral response function
- [punch in - Blue Bridge Cup] day 1 --% 7F format output
- [punch in - Blue Bridge Cup] day 4--------- split ('') cannot be used. There is a space after the last number of test cases. Split ()
- Huawei cloud native - data development and datafactory
- (Reprinted) an article will take you to understand the reproducing kernel Hilbert space (RKHS) and various spaces
- Knowledge - how to build rapport in sales with 3 simple skills
- 《机器人SLAM导航核心技术与实战》第1季:第0章_SLAM发展综述
- Node-RED系列(二八):基于OPC UA节点与西门子PLC进行通讯
- Graduation project EMS office management system (b/s structure) +j2ee+sqlserver8.0
- 第九天 脚本與資源管理
猜你喜欢

Node-RED系列(二八):基于OPC UA节点与西门子PLC进行通讯

Linear interpolation of spectral response function

Green new power and "zero" burden of computing power -- JASMINER X4 series is popular

第十一天 脚本与游戏AI

dotnet-exec 0.5.0 released

El upload Upload file (Manual upload, Automatic upload, upload progress)
![[punch in - Blue Bridge Cup] day 2 --- format output format, ASCII](/img/b2/0059659867e867a32b8e7cef567c8b.jpg)
[punch in - Blue Bridge Cup] day 2 --- format output format, ASCII

云原生——Web实时通信技术之Websocket

DBT product initial experience

Selenium environment installation, 8 elements positioning --01
随机推荐
将DataBinding整合到Activity/Fragment的一种极简方式
thinkphp5实现导入功能
Introduction to cloud native + container concept
各位大佬,flink 1.13.6,mysql-cdc2.2.0,抽取上来的datetime(6)类
Interface test tool postman
Linear interpolation of spectral response function
Unity 在编辑器中输入字符串时,转义字符的输入
Knowledge - how to build rapport in sales with 3 simple skills
What does the hyphen mean for a block in Twig like in {% block body -%}?
【模糊神经网络预测】基于模糊神经网络实现水质预测含Matlab源码
ThingsBoard教程(二三):在规则链中计算二个设备的温度差
errno和perror
Graduation project EMS office management system (b/s structure) +j2ee+sqlserver8.0
[operation] MySQL query operation 2 on May 25, 2022
绿色新动力,算力“零”负担——JASMINER X4系列火爆热销中
节点CODE相同会导致数据重复
第十一天 脚本与游戏AI
王爽-汇编语言 万字学习总结
第十二天 进阶编程技术
The jupyter notebook kernel hangs up frequently and needs to be restarted