/** * Danni's Arduino client on PORT 5099 * */ #include #include #include #include #include #include #include int main(int argc, char *argv[]) { char buffer[255]; int socket_nummer; int laenge; int n; struct sockaddr_in adressinfo; int ergebnis; unsigned short int portnummer = 5099; char ip_adresse[] = "127.0.0.1"; // 127.0.0.1 is the IP address of your local host // char ip_adresse[] = "91.50.191.40"; // address of the server if (argc <= 1) { printf("\nCall client with:\n"); printf("danni_client to send a command to the Arduino or:\n"); printf("danni_client STOP_SERVER to stop the server and close the serial port.\n"); return(0); } socket_nummer = socket(AF_INET, SOCK_STREAM, 0); adressinfo.sin_family = AF_INET; adressinfo.sin_addr.s_addr = inet_addr(ip_adresse); adressinfo.sin_port = htons(portnummer); laenge = sizeof(adressinfo); ergebnis = connect(socket_nummer, (struct sockaddr *)&adressinfo, laenge); if (ergebnis == 0) { n = write(socket_nummer,argv[1],strlen(argv[1])+1); if (n < 0) { error("ERROR writing to socket"); } n = read(socket_nummer,buffer,255); if (n > 0) { printf("%s",buffer); } } else { perror("ERROR connection the server"); } close(socket_nummer); return(0); }