7, LIBGDX network operation

Source: Internet
Author: User
Tags libgdx

(Official website: www.libgdx.cn)

LIBGDX contains a number of cross-platform network operations classes, which are in gdx.net.

features
    • Cross-platform HTTP requests

    • Multi-platform TCP c/S socket support (configurable)

    • TCP/C optimization

    • Cross-platform browser access

Description
    • net.java cross-platform network interface. Get the object of network interaction here.

    • socket.java is an interface that provides the connection status of a remote Socket address.

    • sockethints.java is a TCP server-side interface that is created. Provides a standard accept () method to obtain a connected TCP client.

    • serversockethints.java is a class that configures a TCP server socket.

    • httpstatus.java is a class that looks at network status.

    • httpparameterutils.java is a tool method that provides HTTP requests.

    • httprequestbuilder Create Httprequests class.

To create a TCP client, you can use the following code:
Socket socket = Gdx.net.newClientSocket (Protocol Protocol, String host, int port, sockethints hints);
To create a TCP server side, you can use the following code:
ServerSocket Server = Gdx.net.newServerSocket (Protocol Protocol, int port, serversockethints hints);
To send an HTTP request:
Httprequestbuilder Requestbuilder = new Httprequestbuilder ();
HttpRequest HttpRequest = Requestbuilder.newrequest (). Method (httpmethods.get). URL ("http://www.google.de"). Build () ;
Gdx.net.sendHttpRequest (HttpRequest, Httpresponselistener);

To open the System browser, you can use the following code:
Gdx.net.openURI (String URI)

Note

Need attention when using different platforms.
1. The TCP client and server are used differently in GWT. The reason is that java.net does not support GWT.
2. On some platforms it is not supported to open the system browser because of specific platform limitations.
3. In Android, you must declare permissions to access the network in the Androidmanifest.xml file:
<uses-permission android:name= "Android.permission.INTERNET"/>
4. In Android, you can no longer access the network in the main thread without disabling Strictmode. Prevents the main thread from blocking.
5. Pay attention to traffic in the mobile network
6. Support Network Configuration
7, the power may be exhausted during data transmission.
8, Content-type is set to post.
(www.libgdx.cn All rights reserved, if need to reprint, indicate source)

7, LIBGDX network operation

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.