Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netdb.h>
- #define SIZE 4096
- int main(int argc, char* argv[]) {
- int status = 200;
- int len;
- int sock;
- struct hostent *host;
- struct sockaddr_in server;
- char buffer[SIZE];
- char handshake[] = "raw\r\n\r\n";
- sock = socket(AF_INET, SOCK_STREAM, 0);
- if (sock < 0) {
- exit(-1);
- }
- /* host is deallocated by the socket runtime*/
- if ((host = gethostbyname("127.0.0.1")) == NULL) {
- exit(-1);
- }
- server.sin_family = AF_INET;
- server.sin_port = htons(9090);
- server.sin_addr = *(struct in_addr *) host->h_addr;
- if (0 != connect(sock, (struct sockaddr *) &server, sizeof(server))) {
- exit(-1);
- }
- write(sock, handshake, strlen(handshake));
- len = snprintf(buffer,SIZE,"{\"receiver\":\"/wrtStatus\",\"msg\":{\"data\":%d},\"type\":\"std_msgs/UInt8\"}",status);
- if (len < 0 || len >= SIZE) {
- exit(-1);
- }
- write(sock,"\x00",1);
- write(sock,buffer,len);
- write(sock,"\xFF",1);
- close(sock);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement