当前位置:网站首页>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
边栏推荐
- Huawei cloud native - data development and datafactory
- Collinearity problem
- I spent three years in a big factory outsourcing, which subverted my understanding!
- .NET 7 的 JWT 配置太方便了!
- Green new power and "zero" burden of computing power -- JASMINER X4 series is popular
- 云原生入门+容器概念介绍
- 使用IDEAL连接数据库,运行出来了 结果显示一些警告,这部分怎么处理
- [operation] getting started with MySQL on May 23, 2022
- Pytorch Profiler+ Tensorboard + VS Code
- Interface test tool postman
猜你喜欢

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

Interpretation score of bilstm-crf in NER_ sentence
![[note] on May 27, 2022, MySQL is operated through pychart](/img/34/36a3765683b2af485ca7c3e366da59.png)
[note] on May 27, 2022, MySQL is operated through pychart

解决navicat连接数据库遇到的问题

王爽-汇编语言 万字学习总结

How to analyze and solve the problem of easycvr kernel port error through process startup?

Solve the problem of Navicat connecting to the database

The new paradigm of AI landing is "hidden" in the next major upgrade of software infrastructure

两个月拿到N个offer,什么难搞的面试官在我这里都不算事

Sql语句遇到的错误,求解
随机推荐
Error encountered in SQL statement, solve
(03). Net Maui actual combat basic control
El upload Upload file (Manual upload, Automatic upload, upload progress)
lego_loam 代码阅读与总结
Integrating viewbinding and viewholder with reflection
Sql语句遇到的错误,求解
[punch in - Blue Bridge Cup] day 5 --- lower() small
base64.c
利用反射整合ViewBinding和ViewHolder
How to use Jersey to get the complete rest request body- How to get full REST request body using Jersey?
Error in conditional filter (if) syntax in sum function in SQL Server2005
MySQL updates JSON string in array form
lego_ Reading and summary of loam code
第十天 数据的保存与加载
Use ideal to connect to the database. The results show some warnings. How to deal with this part
Thinkphp5 implements import function
云原生入门+容器概念介绍
[personal summary] learning plan
【笔记】2022.5.23 MySQL
基于ROS的SLAM建图、自动导航、避障(冰达机器人)