serv.cpp
上传用户:sztlpcb
上传日期:2007-06-09
资源大小:741k
文件大小:3k
- #include <windows.h>
- #include <winsock.h> // winsock惠ノぇ夹繷
- #include <stdio.h>
- #include <conio.h>
- #include <process.h>
- #define bufsize 1024
- #define AddrA "234.2.3.4"
- #define AddrB "234.2.3.6"
- WSADATA wsadata;
- void sendmenu(void *tmp);
- int main(int argc,char* argv[])
- {
- int listen_sd,child_sd;
- int len;
- fd_set fdset;
-
- struct sockaddr_in src_addr,child_addr;
- src_addr.sin_family = AF_INET;
- src_addr.sin_port = 7689; /* port number */
- src_addr.sin_addr.s_addr = INADDR_ANY; /* address */
-
- WSAStartup(MAKEWORD(1,1),&wsadata);
- listen_sd = socket(PF_INET,SOCK_STREAM,0);
- bind(listen_sd,(struct sockaddr far *)&src_addr,sizeof(src_addr));
- listen(listen_sd,5);
- FD_ZERO(&fdset);
- FD_SET(listen_sd,&fdset);
- len=sizeof(child_addr);
- while(!kbhit())
- {
- select(FD_SETSIZE,&fdset,NULL,NULL,NULL);
- child_sd=accept(listen_sd,(struct sockaddr far *)&child_addr,&len);
-
- //create thread to send menu
- _beginthread(sendmenu,0,(void *) child_sd);
- //sendmenu(child_sd);
- Sleep(1000);
- //printf("send menun");
- }
-
- closesocket(listen_sd);
- WSACleanup();
- printf("press any key to continuen");
- _getch();
- _getch();
- return 0;
- }
- void sendmenu(void *tmp)
- {
- FILE *menufile;
- char buffer[bufsize]="";
- char choose;
- size_t bufRead = 0;
- SOCKET cli_sock=(SOCKET) tmp;
- int recv_count=0;
- //fd_set cli_fd;
- //timeval time;
-
-
- menufile=fopen("menu.txt","rb");
- if ( menufile == NULL )
- {
- printf( "rCan't Access menufile ");
- }
- (void) fseek( menufile, 0, SEEK_SET );
- while(!feof(menufile))
- {
- bufRead = fread(buffer, sizeof(BYTE), bufsize,menufile);
- printf("read %d from filen",bufRead);
- send(cli_sock,buffer,bufRead,0); //肚癳RTP