Esempio n. 1
0
int main() {
  // std::cout << "Start Main\n";
  aui.OperationLoop();
  return 0;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{

    sock = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
    if(sock < 0)
    {
        printf("创建套接字失败了.\r\n");
        exit(0);
    }
    memset(&fromAddr,0,sizeof(fromAddr));
    fromAddr.sin_family=AF_INET;
    fromAddr.sin_addr.s_addr=htonl(INADDR_ANY);
    fromAddr.sin_port = htons(4000);


    if((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
        perror("Error:socket failed!");
        exit(1);
    }
    memset(&servAddr, 0, sizeof(servAddr));
    servAddr.sin_family = AF_INET;
    servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
    servAddr.sin_port = htons(4000);

    if (bind(s, (struct sockaddr*)&servAddr, sizeof(servAddr)) < 0) {
        perror("Error: bind failed!");
        exit(1);
    }


    // if(bind(sock,(struct sockaddr*)&fromAddr,sizeof(fromAddr))<0)
    // {
    //     printf("bind() 函数使用失败了.\r\n");
    //     close(sock);
    //     exit(1);
    // }

    // while(1){
    //     addrLen = sizeof(toAddr);
    //     __read();
    //     __send();
    // }

    cout << "----------------------------------------------------------------------" << endl;

    //   clntAddr.sin_family = AF_INET;
    //   clntAddr.sin_port = htons(4000);
    //   inet_pton(AF_INET, "172.18.182.152", &clntAddr.sin_addr);

//    int on=1;
//    if((setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&on,sizeof(on)))<0)
//    {
//        perror("setsockopt failed");
//        exit(EXIT_FAILURE);
//    }


    while(1) {

        __read();
//         char tmp[] = "asdfasdf";
//         sendto(s, tmp, sizeof(tmp), 0, (struct sockaddr*)&clntAddr, clntAddrLen);
        string op = buffer;
        cout << op << endl;
        if (op == "root") {

            aui.OperationLoop();
        }
        cout << "the client has quited." << endl;
    }
}