Reprint _ Some experience about MTK socket programming

Source: Internet
Author: User
Tags base64
0. On the emulator, initialization requires the first call to Soc_init_win32 ()
1. Monitoring Msg_id_app_soc_notify_ind messages (Soc_write,soc_read,soc_connect,soc_close)
The last parameter of 2.soc_create: The Cmnet account number is 10,cmwap 14 by default. There's nothing wrong with the simulator. As long as the PC can surf the internet.
3.soc_setsockopt Soc_nbio setting does not block
4.soc_setsockopt Soc_async Setting Async
5.soc_connect,soc_write,soc_read return Soc_wouldblock must wait for 1 of the notification function to be processed. It is best to set the timeout to close the socket.
6. Convert any pointer of data into Short,int
ARM features, the short pointer must be 2 aligned, and the int pointer must be 4 aligned.
Compact data from the network (packed), must support any address conversion to short or int

static int MyInt (unsigned char * p)
{
int A;
((unsigned char *) &a) [0] = p[0];
((unsigned char *) &a) [1] = p[1];
((unsigned char *) &a) [2] = p[2];
((unsigned char *) &a) [3] = p[3];
return A;
}

Static short MyShort (unsigned char * p)
{
Short A;
((unsigned char *) &a) [0] = p[0];
((unsigned char *) &a) [1] = p[1];
return A;
}


HTTP protocol emulation for 7.CMWAP
Cmwap must be proxied via 10.0.0.172:80 port
Go to the HTTP protocol. Typically 1.1

#define Proxyhttprequestheader "post/http/1.1\r\n" "x-online-host:www.abc.com:12345\r\n" "keep-alive:close\r\n" "Content-length:%d\r\n" "\ r \ n"
X-online-host is followed by the target machine network address and port
Content-length the following data length
After the head is followed by the data, it is best to use Base64 encoding.
Server-side received data is generally modified by the mobile gateway.


HTTP emulation for 8.cmwap: server-side return format:

#define Http_response_header "http/1.1 ok\r\n" "Content-length:%d\r\n" "\ r \ n"//Content-length after filling in the subsequent data length
After the head is followed by the data, it is best to use Base64 encoding.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.