#include<iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h> #include<windows.h>
#include <winsock2.h> //*************** SOCKET所需
#pragma comment(lib, "ws2_32.lib") //****************** SOCKET所需
#define MYPORT 6140
#define BUFSIZE 100
void main()
{
int sockfd;
int addr_len;
struct sockaddr_in my_addr;
struct sockaddr_in their_addr;
char buf[BUFSIZE];
WSADATA wsd;
int err;
err = WSAStartup(MAKEWORD(2,2),&wsd);
if((sockfd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1){
printf("socket error/n");
exit(1);
}
my_addr.sin_family=AF_INET;
my_addr.sin_port=htons(MYPORT);
my_addr.sin_addr.s_addr=INADDR_ANY;
//bzero(&(my_addr.sin_zero),8);
if(bind(sockfd,(struct sockaddr *)&my_addr,sizeof(struct sockaddr))==-1){
printf("bind error");
exit(1);
}
listen(sockfd,BUFSIZE);
addr_len=sizeof(struct sockaddr);
while(1){
accept(sockfd,(struct sockaddr *)&their_addr,&addr_len);
}
closesocket(sockfd);
}