Download Nokia M2M Platform M2M System Protocol 2 Socket
Transcript
Parameter Description Socket ID A handle to a socket to be connected Address pointer The address of a socket to which the existing socket is connected Address length The length of the socket address in bytes Table 12. The sp2_connect function call return values Return value Description SP2_SOCKET_OK Socket was connected successfully SP2_SOCKET_ERROR Connection failure An example of connecting a socket: DWORD socketID; // a handle to the socket DWORD status; // a return value from the function struct sp2_sockaddr_in addr; // the address of the socket to be connected addr.sin_family = SP2_AF_INET; // addressing scheme is IPv4 addr.sin_port = sp2_htons(1234); // port to which socket is to be connected addr.sin_addr = sp2_inet_addr(“127.0.0.1”); // a socket address status = sp2_connect(socketID,(sp2_sockaddr *)&addr,sizeof(addr)); if (status == SP2_SOCKET_OK) 5.1.6 Sending data to a socket (sp2_send / sp2_sendto) The sp2_send and sp2_sendto functions write data to a previously connected M2M System Protocol 2 socket. The sp2_send function is used with TCP sockets, and the sp2_sendto function is used with UDP sockets. Both function calls are illustrated in Figure 8. M2M System Protocol 2 Application software Nokia M2M module software sp2_send / sp2_sendto() SEND / SENDTO() Start sending data SEND_RESP() status() 17/46