Announcement

Collapse
No announcement yet.

Send To Host Function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Send To Host Function

    Hello,

    i want to know, how i can connect to a host and send bufferdata....

    my example:

    Code:
    struct sockaddr AddrTo;
    int tcpServerSock = -1;
    
    'define host property
    AddrTo.sa_family = AF_INET;
    AddrTo.sa_data = ""???? // i dont know how works
    /*WHERE I CAN define host ip address and host portaddress?*/
    
    /* create and initialize the TCP socket */
    if ((tcpServerSock = socket(AF_INET, SOCK_STREAM, IPPROTO_IP)) < 0)
    {
       sprintf(buffer, "Error...create and initialize the TCP socket...\r\n");
       SerialWrite(0, buffer, strlen(buffer), true);
       return -1;
    }
    
    sprintf(buffer, "connect TCP socket...\r\n");
    SerialWrite(0, buffer, strlen(buffer), true);
    
    if (connect(tcpServerSock, (struct AddrTo *)&AddrTo, sizeof(AddrTo)) < 0)
    {		
       sprintf(buffer, "Error...bind the TCP socket...\r\n");
       SerialWrite(0, buffer, strlen(buffer), true);
       closesocket(tcpServerSock);
       return -1;
    }
    
    sprintf(buffer, "...Hello CMC Sensor Server...\r\n");
    send(tcpServerSock, buffer, strlen(buffer), 0);
    can anybody help me please?

    thanke with best regards

  • #2
    ok my solution works now...

    is anybody ready this here?

    Code:
    ...
    AddrTo.sin_family = AF_INET; /* Use TCP/IP */
    AddrTo.sin_port = htons(SDK_NETPORT); /* Server port */
    AddrTo.sin_addr.s_addr = NetDottedTo32BitNetworkByteOrder(SERVER_ADDRESS); /* Host address */
    
    ...
    
    /* Waiting here for IP address assignment from the DHCP server. */ DelayThread(0, DLY_MSECS, 2500); 
    
    ...
    
    if (connect(tcpServerSock, (struct sockaddr *)&AddrTo, sizeof(AddrTo)) < 0)
    {		
       sprintf(buffer, "Error: connect to host failed...\r\n");
       SerialWrite(0, buffer, strlen(buffer), true);
       closesocket(tcpServerSock);
       return -1;
    }
    
    /*send to server*/
    sprintf(buffer, "...Hello CMC Sensor Server...\r\n");
    send(tcpServerSock, buffer, strlen(buffer), 0);

    Comment


    • #3
      This looks good. I am glad you were able to figure this out on your own.

      Check out the aestunnelclient.c and aestunnerserver.c samples as well for an example of listening for a connection.

      Comment

      Working...
      X