我有一个,不过是入门阶段的,我自己编的,不好,仅供参考!
解决方案 »
- 请问如何将LPBYTE转换成char
- CSDN有QT版么
- 怎么才能看到ScrollView窗口以外的文字?
- 在Win32的环境中,问一个ListView控件显示的问题
- ××××××××关于自定义空间的消息响应问题×××××××××××
- 如何在程序中调用拨号连接的快捷方式?用ShellExecute函数不行啊
- VC中的ShowMessageBox()函数怎样使用?
- 请教有关关机的API函数
- COM里使用_bstr_t一个小问题
- 请教各位大侠:如何使当鼠标移到Button按钮上时,显示提示信息?
- 谁看过<深入浅出同MFC>,我以前下了一个,好像还有一张光盘,我没找到,可以帮帮吗?
- 为什么只有WINDOWS标准控件或常用控件才能在没有安装过VC的机器上使用?比如CList,CTree,但是.ocx 的第三方控件不能使用?是否要注册?如何注册?
//
#define WIN32_LEAN_AND_MEAN
#include "io.h"
#include <stdio.h>
#include <stdlib.h>
#include <fstream.h>
#include <iostream.h>
#include <winsock2.h>
#include <windows.h>
const VERSION_MAJOR=1;
const VERSION_MINOR=1;
#define REQUEST 400
#define REPLY 400
#define UDP_SERV_PORT 7777
#define TCP_SERV_PORT 8888
#define TTCP_SERV_PORT 9999
int main(int argc, char* argv[])
{
WSADATA WSData;
char request[REQUEST],reply[REPLY];
struct sockaddr_in server,client;
int listenfd,clilen;
SOCKET sockfd;
if(WSAStartup(MAKEWORD(VERSION_MAJOR,VERSION_MINOR),&WSData))
{
printf("cannot find Winsock v%d.%d\n",VERSION_MAJOR,VERSION_MINOR);
return (1);
}
listenfd=socket(PF_INET,SOCK_STREAM,0);
if(listenfd==INVALID_SOCKET)
{
printf("cannot open socket\n");
return (1);
}
server.sin_family=AF_INET;
server.sin_addr.s_addr=htonl(INADDR_ANY);
server.sin_port=htons(TCP_SERV_PORT);
if(bind(listenfd,(struct sockaddr *)&server,sizeof(server))<0)
{
perror("bind failed\n");
return (1);
}
if(listen(listenfd,SOMAXCONN)<0)
{
printf("listen error\n");
return (1);
}
for(;;)
{
clilen=sizeof(client);
if((sockfd=accept(listenfd,(struct sockaddr *)&client,&clilen))<0)
{
printf("accept error\n");
return(1);
}
printf("accept sucess\n");
memset(request,0,REQUEST);
if(recv(sockfd,request,REQUEST,NULL)<0)
{
printf("read error\n");
return 0;
}
printf(request);
printf("\n");
strcpy(reply,"i love you too");
if(send(sockfd,reply,REQUEST,NULL)<0)
{
printf("write error\n");
return 0;
}
close(sockfd);
}
close(listenfd);
return 0;
}