实验一 附件:
//server.cpp
// Server.cpp
// Extremely simple, stream server example. 简单的服务器示例
// Works in conjunction with Client.cpp. 与 Client.cpp 协同工作。
// The program sets itself up as a server using the TCP 设置为使用 TCP 的
服务器
//等待来自客户机的数据,显示传入的数据,向客户端发送消息,然后退出。
// protoocl. It waits for data from a client, displayss
// the incoming data, sends a message back to the client
// and then exits.
// 编译并链接到 wsock32.lib #pragma comment(lib,” wsock32.lib”)s
// Compile and link with wsock32.lib
//
// Pass the port number that the server should bind() to
// on the command line. Any port number not already in use
// can be specified.
//
// Example: Server 2000 以端口号 2000 为例
//
//lib 文件
#pragma comment(lib,"wsock32.lib")
//头文件
#include <stdio.h>//标准输入输出头文件
#include <winsock.h>//相对于 Winsock2.h 的老版本
#include <string.h>//字符串
// Function prototype
//函数声明
void StreamServer(short nPort);
// Helper macro for displaying errors
//输出 error 辅助宏显示错误
#define PRINTERROR(s) \
fprintf(stderr,"\n%: %d\n", s, WSAGetLastError())
评论0