Page 243 - 완) I MDP 프로젝트 작품 보고서(전체과 1학년)1.6
P. 243

if  ((fd  =  serialOpen ("/dev/ttyAMA0",  115200)) < 0)

               {
                 fprintf  (stderr, "Unable to  open  serial  device:  %s\n",  strerror  (errno))  ;
                 return  1  ;
               }



                if  (wiringPiSetup  ()  ==  -1)
               {
                 fprintf  (stdout, "Unable  to  start  wiringPi:  %s\n", strerror (errno))  ;
                 return  1  ;
               }



               if(argc  != 2)
               {
                    printf("usage : %s  [port]\n", argv[0]);
                    exit(0);

               }


                if((server_fd  =  socket(AF_INET,  SOCK_STREAM,  0))  ==  -1)
               {
                    printf("Server  :  Can't  open stream  socket\n");

                    exit(0);
               }
                memset(&server_addr,  0x00,  sizeof(server_addr));


                server_addr.sin_family  =  AF_INET;

                server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
                server_addr.sin_port  =  htons(atoi(argv[1]));


                if(bind(server_fd,  (struct  sockaddr  *)&server_addr,  sizeof(server_addr))  <0)
               {

                    printf("Server  :  Can't  bind local address.\n");
                    exit(0);
               }


               if(listen(server_fd,  5) < 0)

               {




                                                         -  236  -
   238   239   240   241   242   243   244   245   246   247   248