Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <errno.h>
- #include <string.h>
- #include <time.h>
- #include <signal.h>
- #include <sys/wait.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <netdb.h>
- int main(int argc, char **argv) {
- int z, len_inet;
- struct sockaddr_in adr_srvr;
- int sockfd;
- int i;
- char buf[256];
- int buffer[256];
- memset(&adr_srvr, 0, sizeof(adr_srvr));
- if (argc ==2)
- adr_srvr.sin_addr.s_addr = inet_addr(argv[1]);
- adr_srvr.sin_family = AF_INET;
- adr_srvr.sin_port = htons(9090);
- sockfd = socket(AF_INET, SOCK_STREAM, 0);
- if (sockfd == -1) {
- perror("socket error");
- exit(1);
- }
- z = connect(sockfd, (struct sockaddr *)&adr_srvr, sizeof(adr_srvr));
- if(z == -1) {
- perror("connect error");
- exit(1);
- }
- while(1){
- // printf("here");
- //接受SERVER傳送HELLO
- read(sockfd, buf, 256);
- printf("%s\n",buf);
- //告知輸入答案
- read(sockfd, buf, 256);
- printf("%s\n",buf);
- while (1) {
- //讀取輸入
- scanf("%d",&buffer[0]);
- //傳給SERVER
- write(sockfd, buffer, 256);
- //讀取結果
- read(sockfd, buf, 256);
- printf("%s\n",buf);
- if(strlen(buf)==6){
- //如果答案是BINGO,就輸出最小的測測者次數(WINNER)
- read(sockfd, buf, 256);
- printf("%s\n",buf);
- break;
- }
- }
- }
- close(sockfd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement