int main (int argc, char *argv[]) { if (argc != 3) { return 1; } PRFileDesc* socket = PR_NewTCPSocket(); PRNetAddr addr; initAddr(&addr, argv[1], atoi(argv[2])); PR_Connect(socket, &addr, PR_INTERVAL_NO_TIMEOUT); char* string = (char*) malloc(10*sizeof(char)); PR_Recv(socket, string, 10, 0, PR_INTERVAL_NO_TIMEOUT); string[10] = 0; printf("%s\n", string); PR_Close(socket); }
unsigned char SONAR::setAddr(unsigned char addr) { debug(); if(addr==0) { unsigned startTime=millis(); unsigned int delta=0; bool gotKey=false; pinMode(keyS7, INPUT); // 201209 while(digitalRead(keyS7)==KEYPRESSED) { gotKey=true; delay(100); SonarPrint.println(delta=millis()-startTime,DEC); } if(gotKey) { setTX(); SonarPrint.print("GOt KeyS7(ms): "); SonarPrint.println(delta,DEC); } delta/=1000; if(0x1<=delta && delta<=0x30) addr=0x10+delta; } unsigned char addrCmd[sizeof(addrCmdTemplate)]; if(0x11<=addr && addr<=0x30) { generateAddrCmd(addrCmd,addr); sendCmd(addrCmd,sizeof(addrCmd)); delay(1); recvDat(addrDatSize); #ifdef DEBUG showDat(addrDatSize); #endif if(checksum(addrDatSize)==0) { initAddr(addr); return addr; } } return 0; }
SONAR::SONAR(unsigned char addr) { debug(); initAddr(addr); }
int main(int argc, char **argv) { if(argc < 2){ printf("argv error!\n"); printf("try (*.o ip port) again!\n"); exit(EXIT_FAILURE); } /* conntec to the server */ char buf[1024]; int cliSocket = initSocket(); if(-1 == initConnect(cliSocket, initAddr(argv[1], atoi(argv[2])))){ close(cliSocket); exit(EXIT_FAILURE); } memset(buf, 0, sizeof(buf)); recv(cliSocket, buf, 1024, 0); printf("%s\n", buf); if(buf[0] == 'S'){ close(cliSocket); exit(EXIT_FAILURE); } /* start */ while(memset(buf, 0, sizeof(buf)), printf("#"), NULL != fgets(buf, 1024, stdin)){ /* del '\n' */ buf[strlen(buf) - 1] = '\0'; /* handle command */ /* command ls */ if(strcmp(buf, "ls") == 0){ send(cliSocket, buf, strlen(buf), 0); cliLs(cliSocket); } /* command pwd */ else if(strcmp(buf, "pwd") == 0){ send(cliSocket, buf, strlen(buf), 0); cliPwd(cliSocket); } /* command cd */ else if(strncmp(buf, "cd", 2) == 0 && buf[2] == ' '){ send(cliSocket, buf, strlen(buf), 0); } /* command getfiles */ else if(strncmp(buf, "gets", 4) == 0 && buf[4] == ' '){ send(cliSocket, buf, strlen(buf), 0); cliGetFiles(cliSocket, 1); } /* command putsfiles */ else if(strncmp(buf, "puts", 4) == 0 && buf[4] == ' '){ send(cliSocket, buf, strlen(buf), 0); cliPutFiles(cliSocket, buf, 1); } /* command remove */ else if(strncmp(buf, "remove", 6) == 0 && buf[6] == ' '){ send(cliSocket, buf, strlen(buf), 0); cliRemoveFiles(cliSocket); } /* others */ else{ printf("wrong command\n"); } } close(cliSocket); return 0; }