SHARE
TWEET

Informatik_LaborSS18

LUV2XLR8 Apr 18th, 2018 (edited) 12 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2. #include<string.h>    //strlen
  3. #include<sys/socket.h>
  4. #include<arpa/inet.h> //inet_addr
  5.  
  6. int main(int argc , char *argv[])
  7. {  
  8.    
  9.     int socket_desc;
  10.     struct sockaddr_in server;
  11.     char *message , server_reply[2000];
  12.      
  13.     //Create socket
  14.     socket_desc = socket(AF_INET , SOCK_STREAM , 0);
  15.     if (socket_desc == -1)
  16.     {
  17.         printf("Could not create socket");
  18.     }
  19.          
  20.     server.sin_addr.s_addr = inet_addr("10.123.45.1");
  21.     server.sin_family = AF_INET;
  22.     server.sin_port = htons( 2000 );
  23.  
  24.     //Connect to remote server
  25.     if (connect(socket_desc , (struct sockaddr *)&server , sizeof(server)) < 0)
  26.     {
  27.         puts("connect error");
  28.         return 1;
  29.     }
  30.      
  31.     puts("Connected\n");
  32.      
  33.    
  34.     //Receive a reply from the server
  35.     for (int i; i< 2; i++)
  36.     {
  37.     if( recv(socket_desc, server_reply , 2000 , 0) < 0)
  38.     {
  39.         puts("recv failed");
  40.     }
  41.     puts("Reply received\n");
  42.     puts(server_reply);
  43.    
  44.  
  45.      
  46.     }
  47.      
  48.     return 0;
  49. }
  50.  
  51. /*
  52.    1. 1x Chipbezeichnung
  53.  * 2. 1xtemp
  54.  * 3. 3x acceleration
  55.  * 1x gyro
  56.  * 3xmag
  57.  *
  58.  */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top