Package com.badlogic.gdx
Interface Net
-
public interface NetProvides methods to perform networking operations, such as simple HTTP get and post requests, and TCP server/client socket communication. To perform an HTTP request create aNet.HttpRequestwith the HTTP method (seeNet.HttpMethodsfor common methods) and invokesendHttpRequest(HttpRequest, HttpResponseListener)with it and aNet.HttpResponseListener. After the HTTP request was processed, theNet.HttpResponseListeneris called with aNet.HttpResponsewith the HTTP response values and an status code to determine if the request was successful or not. To create a TCP client socket to communicate with a remote TCP server, invoke thenewClientSocket(Protocol, String, int, SocketHints)method. The returnedSocketoffers anInputStreamandOutputStreamto communicate with the end point. To create a TCP server socket that waits for incoming connections, invoke thenewServerSocket(Protocol, int, ServerSocketHints)method. The returnedServerSocketoffers anServerSocket.accept(SocketHints options)method that waits for an incoming connection.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceNet.HttpMethodsProvides common HTTP methods to use when creating aNet.HttpRequest.static classNet.HttpRequestContains getters and setters for the following parameters: httpMethod: GET or POST are most common, can useHttpMethodsfor static references url: the url headers: a map of the headers, setter can be called multiple times timeout: time spent trying to connect before giving up content: A string containing the data to be used when processing the HTTP request. Abstracts the concept of a HTTP Request:static interfaceNet.HttpResponseHTTP response interface with methods to get the response data as a byte[], aStringor anInputStream.static interfaceNet.HttpResponseListenerListener to be able to do custom logic once theNet.HttpResponseis ready to be processed, register it withsendHttpRequest(HttpRequest, HttpResponseListener).static classNet.Protocol
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidcancelHttpRequest(Net.HttpRequest httpRequest)SocketnewClientSocket(Net.Protocol protocol, java.lang.String host, int port, SocketHints hints)Creates a new TCP client socket that connects to the given host and port.ServerSocketnewServerSocket(Net.Protocol protocol, int port, ServerSocketHints hints)Creates a new server socket on the given port, using the givenNet.Protocol, waiting for incoming connections.ServerSocketnewServerSocket(Net.Protocol protocol, java.lang.String hostname, int port, ServerSocketHints hints)Creates a new server socket on the given address and port, using the givenNet.Protocol, waiting for incoming connections.booleanopenURI(java.lang.String URI)Launches the default browser to display a URI.voidsendHttpRequest(Net.HttpRequest httpRequest, Net.HttpResponseListener httpResponseListener)Process the specifiedNet.HttpRequestand reports theNet.HttpResponseto the specifiedNet.HttpResponseListener.
-
-
-
Method Detail
-
sendHttpRequest
void sendHttpRequest(Net.HttpRequest httpRequest, @Null Net.HttpResponseListener httpResponseListener)
Process the specifiedNet.HttpRequestand reports theNet.HttpResponseto the specifiedNet.HttpResponseListener.- Parameters:
httpRequest- TheNet.HttpRequestto be performed.httpResponseListener- TheNet.HttpResponseListenerto call once the HTTP response is ready to be processed. Could be null, in that case no listener is called.
-
cancelHttpRequest
void cancelHttpRequest(Net.HttpRequest httpRequest)
-
newServerSocket
ServerSocket newServerSocket(Net.Protocol protocol, java.lang.String hostname, int port, ServerSocketHints hints)
Creates a new server socket on the given address and port, using the givenNet.Protocol, waiting for incoming connections.- Parameters:
hostname- the hostname or ip address to bind the socket toport- the port to listen onhints- additionalServerSocketHintsused to create the socket. Input null to use the default setting provided by the system.- Returns:
- the
ServerSocket - Throws:
GdxRuntimeException- in case the socket couldn't be opened
-
newServerSocket
ServerSocket newServerSocket(Net.Protocol protocol, int port, ServerSocketHints hints)
Creates a new server socket on the given port, using the givenNet.Protocol, waiting for incoming connections.- Parameters:
port- the port to listen onhints- additionalServerSocketHintsused to create the socket. Input null to use the default setting provided by the system.- Returns:
- the
ServerSocket - Throws:
GdxRuntimeException- in case the socket couldn't be opened
-
newClientSocket
Socket newClientSocket(Net.Protocol protocol, java.lang.String host, int port, SocketHints hints)
Creates a new TCP client socket that connects to the given host and port.- Parameters:
host- the host addressport- the porthints- additionalSocketHintsused to create the socket. Input null to use the default setting provided by the system.- Throws:
GdxRuntimeException- in case the socket couldn't be opened
-
openURI
boolean openURI(java.lang.String URI)
Launches the default browser to display a URI. If the default browser is not able to handle the specified URI, the application registered for handling URIs of the specified type is invoked. The application is determined from the protocol and path of the URI. A best effort is made to open the given URI; however, since external applications are involved, no guarantee can be made as to whether the URI was actually opened. If it is known that the URI was not opened, false will be returned; otherwise, true will be returned.- Parameters:
URI- the URI to be opened.- Returns:
- false if it is known the uri was not opened, true otherwise.
-
-