How to Establish TCP/IP communication on the mobile phone platform

Source: Internet
Author: User
By http://blog.csdn.net/kaiming2008/archive/2009/02/25/3934203.aspx

I. Characteristics of TCP/IP communication on mobile phones

1. Poor communication stability. Mobile phone communication is far less stable than PC. Mobile phone communication is a wireless communication, which is greatly affected by the signal and quality of mobile phones. Sometimes, when the network is busy, the communication may be blocked, therefore, stability issues in design are often the focus of consideration;

2. The implementation methods vary greatly depending on the platform. Currently, mobile phone platforms are varied and communication implementation methods are different, but they can be divided into the following categories: Synchronous blocking, synchronous non-blocking, asynchronous non-blocking, and asynchronous blocking, blocking is rare. For several common APIs of socket, the methods used on different platforms are also different. Some platforms do not even support some common APIS;

3. Special communication methods. For example, a GSM mobile phone can communicate through a GPRS serial number connection. If it is a China Mobile Phone, the GPRS serial number is divided into two methods: cmwap and cmnet. In fact, both methods are similar, however, cmwap has multiple intermediate servers, and the design of this intermediate server varies with each other. Therefore, cmwap can be used for communication in some places, while cmwap may be difficult to use in some places;

4. Slow communication speed. The current mobile phone communication speed is similar to or even slower than the previous PC's telephone line dialing speed. With the emergence of 3G mobile phones, the speed of mobile phone access will be greatly improved;

5. The communication process is prone to interference from other communications. For example, the communication is often interrupted by the power or SMS.

 

2. Common steps for establishing communications

1. Create a socket. On Some platforms, you can enter the ID of the current application. In asynchronous mode, you may need to register some socket events after creating a socket;

2. Set the socket. On Some platforms, you can set the size of the buffer to be sent, the buffer to be received, the timeout length, and the socket close mode, however, note that not every platform supports these settings. Therefore, it is best to retrieve these settings to check whether the settings are successful;

3. DNS resolution. Some platforms will report back after DNS resolution is successful through the message mechanism, and some platforms will be blocked until the DNS is successful, however, some platforms may require you to perform DNS resolution repeatedly until the DNS resolution is successful;

4. Connect to the server. It is normal to re-connect the phone repeatedly. Do not expect that the connection will be successful every time. If the connection fails, it is necessary to re-connect the phone several times because of the poor communication stability, sometimes it may not be connected at once;

5. Send data. Because the mobile phone communication speed is slow, do not send too much data at once. It is best to send the data in batches with a small amount of data, especially when the cmwap communication is used, the failure rate of communication with large data volumes is the highest, if the platform supports the select method, it is best to use the select method to check whether the data can be sent before each transmission, so the communication implemented in the synchronous mode needs to be done in this way;

6. receive data. For asynchronous mode, a previously received event usually indicates that data has arrived. For synchronous mode, if the platform supports the select method, it is also best to use this method to check whether any data can be received;

7. Disable socket. On Some platforms, you must first shut down the connection before closing the socket.

In addition, if the communication requires GPRS connection support, ensure that GPRS is enabled before establishing the communication, and disable the GPRS operation after the communication ends.

 

Iii. problems that may occur during communication debugging

1. Unable to connect to the server. The possible cause is that the connection function parameter is set incorrectly, the connection address is set incorrectly, or the mobile phone is in arrears, or you have not activated the internet service function. For cmwap, you need to apply for activation first, or the GPRS method is incorrect. (If you want to connect to the gateway, you should enable GPRS in cmwap mode, if you want to directly connect to the server, use cmnet to open GPRS );

2. Open and Close the socket frequently, and the socket creation fails. The possible cause is: improper method of closing the socket;

3. The next communication will fail after the user cancels the operation. The possible cause is that the method is incorrect when the user cancels the exit. If the socket is not closed or the GPRS is not closed;

4. failed to send data packets, probably because the connection is unsuccessful, the data packet is too large to be sent to the WAP gateway, the remote server is disconnected, or the connect reset error occurs;

5. failed to receive data packets or received only one part of the data. The possible cause is that the connect reset error occurs. If the data is received through the gateway, the gateway may be disconnected;

6. When the power supply of the mobile phone is insufficient, the communication may fail because the signal of the mobile phone is too weak.

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.