ClientServer socket编程.doc
《ClientServer socket编程.doc》由会员分享,可在线阅读,更多相关《ClientServer socket编程.doc(4页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Server/Client socket编程/ 客户端#include #include #include #include using namespace std;#pragma comment(lib,ws2_32.lib)#define LEN 100#define SERVER_PORT 10000int main() WSADATA wsaData; int iResult;char dataLEN + 1;SOCKET sockfd;sockaddr_in saddr; iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); if (iRes
2、ult != NO_ERROR) cerr WSAStartup failed: iResult endl;return 1; sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (sockfd = INVALID_SOCKET) cerr Error at socket(): WSAGetLastError() endl; WSACleanup(); return 1; saddr.sin_family = AF_INET; saddr.sin_addr.s_addr = inet_addr(127.0.0.1); saddr.sin
3、_port = htons(SERVER_PORT); iResult = connect(sockfd, (sockaddr*)&saddr, sizeof(saddr);if (iResult = SOCKET_ERROR) closesocket (sockfd); cerr Unable to connect to server: WSAGetLastError() endl; WSACleanup(); return 1; strcpy(data, i am a client);iResult = send(sockfd, data, strlen(data), 0);if (iRe
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ClientServer socket编程 socket 编程
限制150内