From: badlogic Date: Mon, 23 Sep 2013 17:15:34 +0000 (+0200) Subject: tested net stuff on iOS, works X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=8555ef10f6c2073092b8b200a94b9ab8e727a6eb;p=mikumikustudio%2Flibgdx-mikumikustudio.git tested net stuff on iOS, works --- diff --git a/backends/gdx-backend-robovm/todos.txt b/backends/gdx-backend-robovm/todos.txt index 8237d95bc..277a26205 100644 --- a/backends/gdx-backend-robovm/todos.txt +++ b/backends/gdx-backend-robovm/todos.txt @@ -1,6 +1,7 @@ General - see issue tracker, RoboVM specific issues are marked with [RoboVM] - OGG is currently not supported by ObjectAL + - Update: Vibration is not really supported on iOS - IOSApplication.java - getClipboard() not implemented properly, should at least support strings @@ -9,10 +10,6 @@ General - add compass - add useGL2, requires implementation of GL10/GL11 for ios, and fixes in IOSGraphics -- IOSAudo - - newAudioDevice(), new AudioRecorder() not implemented - - OGG not supported, see if we can add that to ObjectAL - - IOSGraphics - need to store current device orientation for Input#getOrienation and consorts - Add support for GL10/GL11 @@ -20,16 +17,12 @@ General - IOSInput - getAzimuth(), getPitch(), getRoll(), getRotationMatrix() need to be implemented and output the same as android - - vibrate(), cancelVibrate() needs to be implemented - see if we can programmatically show the keyboard and receive key events, if so map to gdx keycodes - getPlaceholderTextInput() needs to be implemented - add compass support, fix up isPeripheralAvailable(), including onscreen keyboard stuff - -- IOSMusic - - OGG support - -- IOSNet - - check if that actually works as intended + +- IOSAudo + - newAudioDevice(), new AudioRecorder() not implemented - IOSSound - add support for manipulating an already playing sound instance, seems to work through ALSource diff --git a/tests/gdx-tests-iosrobovm/src/com/badlogic/gdx/tests/IOSRobovmTests.java b/tests/gdx-tests-iosrobovm/src/com/badlogic/gdx/tests/IOSRobovmTests.java index dffd56d74..46b405627 100644 --- a/tests/gdx-tests-iosrobovm/src/com/badlogic/gdx/tests/IOSRobovmTests.java +++ b/tests/gdx-tests-iosrobovm/src/com/badlogic/gdx/tests/IOSRobovmTests.java @@ -5,6 +5,7 @@ import org.robovm.cocoatouch.uikit.UIApplication; import com.badlogic.gdx.backends.iosrobovm.IOSApplication; import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration; +import com.badlogic.gdx.tests.net.PingPongSocketExample; public class IOSRobovmTests extends IOSApplication.Delegate { class InnerClass { @@ -13,7 +14,7 @@ public class IOSRobovmTests extends IOSApplication.Delegate { @Override protected IOSApplication createApplication() { IOSApplicationConfiguration config = new IOSApplicationConfiguration(); - return new IOSApplication(new BulletTestCollection(), config); + return new IOSApplication(new PingPongSocketExample(), config); } public static void main(String[] argv) { diff --git a/tests/gdx-tests-lwjgl/src/com/badlogic/gdx/tests/lwjgl/LwjglDebugStarter.java b/tests/gdx-tests-lwjgl/src/com/badlogic/gdx/tests/lwjgl/LwjglDebugStarter.java index 9b9810075..2726c39e7 100644 --- a/tests/gdx-tests-lwjgl/src/com/badlogic/gdx/tests/lwjgl/LwjglDebugStarter.java +++ b/tests/gdx-tests-lwjgl/src/com/badlogic/gdx/tests/lwjgl/LwjglDebugStarter.java @@ -41,6 +41,7 @@ import com.badlogic.gdx.tests.g3d.ModelLoaderTest; import com.badlogic.gdx.tests.g3d.ModelTest; import com.badlogic.gdx.tests.g3d.ShaderCollectionTest; import com.badlogic.gdx.tests.g3d.voxel.VoxelTest; +import com.badlogic.gdx.tests.net.NetAPITest; import com.badlogic.gdx.tests.utils.GdxTest; public class LwjglDebugStarter { @@ -52,7 +53,7 @@ public class LwjglDebugStarter { // new SharedLibraryLoader("../../extensions/gdx-controllers/gdx-controllers-desktop/libs/gdx-controllers-desktop-natives.jar").load("gdx-controllers-desktop"); // new SharedLibraryLoader("../../gdx/libs/gdx-natives.jar").load("gdx"); - GdxTest test = new ShaderCollectionTest(); + GdxTest test = new NetAPITest(); LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); config.useGL20 = test.needsGL20(); config.width = 1024; diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/net/HttpRequestExample.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/net/HttpRequestExample.java new file mode 100644 index 000000000..b33913ade --- /dev/null +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/net/HttpRequestExample.java @@ -0,0 +1,34 @@ +package com.badlogic.gdx.tests.net; + +import com.badlogic.gdx.ApplicationAdapter; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Net.HttpMethods; +import com.badlogic.gdx.Net.HttpRequest; +import com.badlogic.gdx.Net.HttpResponse; +import com.badlogic.gdx.Net.HttpResponseListener; +import com.badlogic.gdx.tests.utils.GdxTest; + +/** + * Demonstrates how to perform a simple HTTP request. + * Need to add internet permission to AndroidManifest.xml. + * @author badlogic + * + */ +public class HttpRequestExample extends GdxTest { + @Override + public void create() { + HttpRequest request = new HttpRequest(HttpMethods.GET); + request.setUrl("http://libgdx.badlogicgames.com/nightlies/dist/AUTHORS"); + Gdx.net.sendHttpRequest(request, new HttpResponseListener() { + @Override + public void handleHttpResponse(HttpResponse httpResponse) { + Gdx.app.log("HttpRequestExample", "response: " + httpResponse.getResultAsString()); + } + + @Override + public void failed(Throwable t) { + Gdx.app.error("HttpRequestExample", "something went wrong", t); + } + }); + } +} diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/net/OpenBrowserExample.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/net/OpenBrowserExample.java new file mode 100644 index 000000000..824c00cda --- /dev/null +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/net/OpenBrowserExample.java @@ -0,0 +1,18 @@ +package com.badlogic.gdx.tests.net; + +import com.badlogic.gdx.ApplicationAdapter; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.tests.utils.GdxTest; + +/** + * Demonstrates how to open a browser and load + * a specific URL. + * @author badlogic + * + */ +public class OpenBrowserExample extends GdxTest { + @Override + public void create() { + Gdx.net.openURI("http://libgdx.badlogicgames.com"); + } +} diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/net/PingPongSocketExample.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/net/PingPongSocketExample.java new file mode 100644 index 000000000..56ac5db4a --- /dev/null +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/net/PingPongSocketExample.java @@ -0,0 +1,62 @@ +package com.badlogic.gdx.tests.net; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +import com.badlogic.gdx.ApplicationAdapter; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Net.Protocol; +import com.badlogic.gdx.net.ServerSocket; +import com.badlogic.gdx.net.ServerSocketHints; +import com.badlogic.gdx.net.Socket; +import com.badlogic.gdx.net.SocketHints; +import com.badlogic.gdx.tests.utils.GdxTest; + +/** + * Demonstrates how to do very simple socket programming. Implements + * a classic PING-PONG sequence, client connects to server, sends + * message, server sends message back to client. Both client + * and server run locally. We quit as soon as the client + * received the PONG message from the server. This example + * won't work in HTML. Messages are delimited by the new line character, + * so we can use a {@link BufferedReader}. + * @author badlogic + * + */ +public class PingPongSocketExample extends GdxTest { + @Override + public void create() { + // setup a server thread where we wait for incoming connections + // to the server + new Thread(new Runnable() { + @Override + public void run() { + ServerSocketHints hints = new ServerSocketHints(); + ServerSocket server = Gdx.net.newServerSocket(Protocol.TCP, 9999, hints); + // wait for the next client connection + Socket client = server.accept(null); + // read message and send it back + try { + String message = new BufferedReader(new InputStreamReader(client.getInputStream())).readLine(); + Gdx.app.log("PingPongSocketExample", "got client message: " + message); + client.getOutputStream().write("PONG\n".getBytes()); + } catch (IOException e) { + Gdx.app.log("PingPongSocketExample", "an error occured", e); + } + } + }).start(); + + // create the client send a message, then wait for the + // server to reply + SocketHints hints = new SocketHints(); + Socket client = Gdx.net.newClientSocket(Protocol.TCP, "localhost", 9999, hints); + try { + client.getOutputStream().write("PING\n".getBytes()); + String response = new BufferedReader(new InputStreamReader(client.getInputStream())).readLine(); + Gdx.app.log("PingPongSocketExample", "got server message: " + response); + } catch (IOException e) { + Gdx.app.log("PingPongSocketExample", "an error occured", e); + } + } +} \ No newline at end of file