#include <winsock2.h>
#include <stdio.h>
#pragma comment (lib, "ws2_32.lib")
void main()
{
WORD wVersionRequired;
WSADATA wsaData;
int err;
wVersionRequired = MAKEWORD(1,1);
err = WSAStartup( wVersionRequired, &wsaData );
if ( err !=0 )
{
printf("error");
return;
}
if (LOBYTE( wsaData.wVersion ) != 1 || HIBYTE( wsaData.wVersion) != 1)
{
WSACleanup();
return;
}
SOCKET sockSrv = socket( AF_INET, SOCK_STREAM,0 );
SOCKADDR_IN addrSrv;
addrSrv.sin_addr.S_un.S_addr= htonl(INADDR_ANY);
addrSrv.sin_family = AF_INET;
addrSrv.sin_port=htons(5000);
bind(sockSrv,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));
listen(sockSrv,5);
SOCKADDR_IN addrClient;
int len= sizeof(SOCKADDR);
while (1)
{
SOCKET sockConn = accept( sockSrv, (SOCKADDR*)&addrClient, &len);
char sendBuf[100];
char message[1000];
scanf("%s", message);
sprintf( sendBuf,message,inet_ntoa(addrClient.sin_addr));
send( sockConn,sendBuf,strlen(sendBuf)+1, 0 );
char recvBuf[100];
recv( sockConn, recvBuf, 100, 0);
printf("%s\n",recvBuf);
closesocket(sockConn);
}
}
不想起名525
- 粉丝: 3
- 资源: 5
最新资源
- new_bird_c-c语言入门
- christmasTree-圣诞树html网页代码
- working-shell脚本入门——流程控制
- hadoop_install-sqoop数据导入
- ThinkCMF-mysql安装
- BigData-Notes-sqoop的安装与配置
- C语言-leetcode题解之28-implement-strstr.c
- C语言-leetcode题解之27-remove-element.c
- C语言-leetcode题解之26-remove-duplicates-from-sorted-array.c
- C语言-leetcode题解之24-swap-nodes-in-pairs.c
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈