Use the cmwap Access Point of GPRS for network communication 1-establish a connection

Source: Internet
Author: User

using GPRS cmwap access point to achieve network communication 1 ----- establish a connection
for the comparison of wireless access methods, see http://www.cnblogs.com/yoyolion/archive/2007/05/26/760807.html
cmwap as a low-cost wireless access method, it has great application value. This article discusses how to use the cmwap Access Point of GPRS to implement network communication and send and receive custom data.
environment and platform:
the server has a public IP address, which is set to 100.200.300.400 and port 1000. (To simplify it as much as possible, there should be no difference if you do not use a domain name)
Test Platform: Server Windows 2000 Server, client Pocket PC 2003 sencond edition (Windows ce.net 4.2), developed with VC ++ 2005 (mfc8.0)
when a pocket ie request is used to access http: // 100.200.300.400: 1000, the server receives the following data:

Get, HTTP, 1.1
HOST: 100.200.300.400: 1000
Accept: */*, text/X-vCard, text/X-vcalendar, image/GIF, image/vnd. WAP. wbmp
Accept-language: ZH-CN
UA-OS: Windows CE (Pocket PC)-version 4.21
UA-color: color16
UA-pixels: 240x320
UA-CPU: Intel (r) pxa272.
UA-voice: True
UA-language: Javascript
Accept-encoding: gzip, deflate
Content-Length: 0
Via: WTP/1.1 BJBJ-P-GW06-WAP.bj.monternet.com (Nokia WAP Gateway 4.0/CD3/4.1.79)
X-forwarded-for: 10.12.239.87
X-source-ID: ggsn
X-Nokia-CONNECTION_MODE: TCP
X-Up-bearer-type: GPRS
X-Nokia-gateway-ID: nwg/4.1/build04
Connection: Close

 
We can see that it is a common HTTP request.
 
The client sends a request to 100.200.300.400: 1000.Code(For clarity, error handling is omitted)

Socket m_socket;
Socket = socket (af_inet, sock_stream, ipproto_tcp); // TCP socket

Struct sockaddr_in m_severaddr; // server address
M_severaddr.sin_family = af_inet;
M_severaddr.sin_addr.s_addr = inet_addr ("10.0.0.172"); // ip address of the cmwap Proxy Server
M_severaddr.sin_port = htons (80); // Port
 
Connect (m_socket, (sockaddr *) & m_severaddr, sizeof (m_severaddr ));
 
Char request [100];
// The following is an HTTP request. It must end with a blank line (\ r \ n). For details, refer to the HTTP protocol.
Sprintf (request, "% s", "Get http: // 100.200.300.400: 1000 HTTP/1.1 \ r \ n ");
 
Send (m_socket, request, Len, 0); // send the request

Connect establishes a connection with the cmwap proxy server and communicates with the server through the proxy server. After sending is successfully executed (get http: // 100.200.300.400: 1000 HTTP/1.1 ), the server soon received the request packet, as shown below:

Get, HTTP, 1.1
HOST: 100.200.300.400: 1000
Content-Length: 0
Via: WTP/1.1 BJBJ-P-GW13-WAP.bj.monternet.com (Nokia WAP Gateway 4.0/CD3/4.1.79)
X-forwarded-for: 10.12.104.128
X-source-ID: ggsn
X-Nokia-CONNECTION_MODE: TCP
X-Up-bearer-type: GPRS
X-Nokia-gateway-ID: nwg/4.1/build04
Accept :*/*
Connection: Close
 

We can see that the cmwap Proxy Server adds some header information for the request get http: // 100.200.300.400: 1000 HTTP/1.1, mainly the gateway address BJBJ-P-GW13-WAP.bj.monternet.com, which should be called the dynamic server URL.
 
If you use GPRS For The First Time After resetting or switching the network, you may receive a message from the cmwap Proxy Server:

HTTP/1.1 200 OK, success
Content-Length: 725
Content-Type: text/vnd. WAP. WML; charsets = UTF-8
Date: sat, 26 May 2007 02:40:06 GMT
Pragma: No-Cache
Server: WebLogic Server 8.1 SP3 Tue Jun 29 23:11:19 PDT 2004 404973 with CRS:
Cache-control: No-store, no-cache, must-revalidate, Max-age = 0

<? XML version = "1.0" encoding = "UTF-8"?> <! Doctype WML public "-// wapforum // dtd wml 1.1 // en" http://www.wapforum.org/DTD/wml_1.1.xml "> <WML>

I am using Shanghai mobile's shenzhouxing cmwap monthly subscription card. The prompt message is Shanghai Mobile reminding the client to confirm whether Internet access is required, it may be to avoid traffic charges due to the customer's unintentional use of GPRS. This prompt only appears when GPRS is used for the first time after the network is reset or switched, and will not appear after connection. This prompt should be related to a specific network provider. This prompt may not be displayed when you use monthly subscription cards from other provinces.

During specific processing, you can first determine whether the prompt exists. If yes, call send (m_socket, request, Len, 0) again to send the request.

in this way, you can send a request to the cmwap proxy server through connet to establish a connection with the target server 100.200.300.400: 1000. Of course, this connection is indirect.

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.