GPRS network programming

Source: Internet
Author: User

I. Introduction to GPRS

GPRS is short for General Packet Radio Service. It breaks through the way in which GSM networks can only provide circuit switching, only adding corresponding functional entities and performing partial transformation of the existing base station system to achieve group exchange, the investment in this transformation is relatively small, but the user data rate is considerable. General Packet Radio Service (GPRS) is a data transmission technology based on the global mobile phone system (GSM). It can be said that it is a continuation of GSM. GPRS is different from the previous method of continuous channel transmission. It is transmitted in packet mode. Therefore, the user's cost is calculated based on the unit of data transmission, rather than the entire channel, theoretically, it is cheaper.

Currently, GPRS has been widely used. In daily life, mobile phones, PDAs, and PCs can be used for wireless internet entertainment and query. It provides mobile office, map navigation, and other functions at work, these features greatly facilitate our work, so that we can complete our work at any time.

 

Ii. How to start GPRS on PDA

You can set the PDA connection to GPRS access in the connection, but you must set it to cmnet. Do not set the CSD number.

 

3. How to passProgramCall GPRS

There are two common methods for PDA to access the Internet. One is to connect to the Internet through Microsoft activesyn and the other is to connect to the Internet through GPRS or Bluetooth. Generally, only one network connection mode is supported on the PDA. Therefore, when starting a GPRS network, you must first determine whether the network has been connected to the Internet. If the network has been connected, the GPRS connection cannot be started.

To enable the GPRS function on PDA, in addition to using the built-in Internet tools such as the Internet browser, you can use your own programs to start the GPRS function.

When using a program to start GPRS, it involves Ras network programming. Therefore, you must first include the header file.

# Include <initguid. h>

# Include <connmgr. h>

# Include "RAS. H"

Next, determine whether there is a (GPRS) Network: If you want to determine whether the GPRS network is enabled, first list all network connections and determine which one is activated. Generally, when a PDA is connected to a Microsoft activesyn network, other methods cannot be started. Therefore, it does not make much sense to determine which Internet access method is used, here I will directly determine if the PDA is connected to Ineternet;

1: Determine whether to connect to the network

Define parameters: DWORD dwerror, dwrasconnsize, dwnumconnections; rasconn [20]; // This parameter stores the active Ras connection if (dwerror = rasenumconnections (rasconn, & dwrasconnsize, & dwnumconnections) Return-1; // This indicates that the connection cannot be established. If the return parameter of dwnumconnections is 0, it indicates that no network connection exists. If the return parameter is not 0, the existing network connection is terminated, start GPRS. 2: disconnect all remote access if (dwerror = rashangup (rasconn [Index]. hrasconn) Return-1; else return 0; // close 3; Connect to GPRS

Use the connmgrestablishconnectionsync function to apply for a request. The connection type is mainly set according to the first parameter.

 

4. Use wininet to download and upload data through GPRS

Winnet is used for network transmission of small data volumes. Follow the General download process during the download process

First, you must set the connection restrictions for sending data, receiving data, and accessing the server at the same time.

1. Create a cinternetsession object

Cinternetsession inetsession (_ T (""));

Chttpconnection * phttpconn = NULL;

Chttpfile * phttpfile = NULL;

2. Set connection server timeout and restrictions

For example, inetsession. setoption (internet_option_max_conns_per_server, & uparam, sizeof (INT ));

The first parameter indicates the set type. Here we mainly set

Request server time internet_option_connect_timeout

Data sending time-internet_option_send_timeout,

The time when internet_option_receive_timeout,

Server connection count: internet_option_max_conns_per_server, internet_option_max_conns_per_1_0_server;

3. Call chttpconnection: openrequest to create a chttpfile object.

4. Send data: chttpfile: addrequestheaders

Chttpfile: sendrequest

The timeout value can be set only when the network is normal. For details, see the precautions;

5. Accept the data to save the file

Use chttpfile: queryinfo to accept the returned data and determine the parameter value range. If the range is correct, the read data is saved to the file. Note the conversion of byte conversion.

6: exception handling can capture all exceptions as programs are more stable.

 

5. Notes:

I. Due to unstable connections and disconnection between wireless networks and remote servers through GPRS, network traffic fails due to the unstable GPRS network in the current region.

2. If the network is unstable or the network is suddenly disconnected, an error occurs when you use winnet to connect to the network. If the network is exited due to instability or the network times out, the user interface may be congested or exited.

Iii. When connecting to the server using winnet multithreading, you must set the maximum number of connections running TCP/IP; otherwise, some threads may block the returned timeout and other errors.

Solution:

(1) When establishing a TCP connection, you must consider the possible errors in each step, for example, connection failures caused by the absence of a good device connection or poor network signal quality, therefore, two points must be implemented during program design. One is to start the GPRS connection when the program starts; the other is to obtain and handle all possible errors during network communication, at the same time, you also need to dock the returned string for judgment. If the operation is displayed successfully, go to the next step.

(2) due to network instability, setting the timeout time for sending data is invalid (Microsoft confirmed the bug). I have tested it here. Generally, the function will return within 2-3 minutes, because PDAs cannot be called asynchronously, I will force the network connection thread to be closed if no result is returned three minutes later.

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.