OSDN Git Service

tested net stuff on iOS, works
authorbadlogic <badlogicgames@gmail.com>
Mon, 23 Sep 2013 17:15:34 +0000 (19:15 +0200)
committerbadlogic <badlogicgames@gmail.com>
Mon, 23 Sep 2013 17:15:34 +0000 (19:15 +0200)
backends/gdx-backend-robovm/todos.txt
tests/gdx-tests-iosrobovm/src/com/badlogic/gdx/tests/IOSRobovmTests.java
tests/gdx-tests-lwjgl/src/com/badlogic/gdx/tests/lwjgl/LwjglDebugStarter.java
tests/gdx-tests/src/com/badlogic/gdx/tests/net/HttpRequestExample.java [new file with mode: 0644]
tests/gdx-tests/src/com/badlogic/gdx/tests/net/OpenBrowserExample.java [new file with mode: 0644]
tests/gdx-tests/src/com/badlogic/gdx/tests/net/PingPongSocketExample.java [new file with mode: 0644]

index 8237d95..277a262 100644 (file)
@@ -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
index dffd56d..46b4056 100644 (file)
@@ -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) {
index 9b98100..2726c39 100644 (file)
@@ -41,6 +41,7 @@ import com.badlogic.gdx.tests.g3d.ModelLoaderTest;
 import com.badlogic.gdx.tests.g3d.ModelTest;\r
 import com.badlogic.gdx.tests.g3d.ShaderCollectionTest;\r
 import com.badlogic.gdx.tests.g3d.voxel.VoxelTest;\r
+import com.badlogic.gdx.tests.net.NetAPITest;\r
 import com.badlogic.gdx.tests.utils.GdxTest;\r
 \r
 public class LwjglDebugStarter {\r
@@ -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");\r
 //             new SharedLibraryLoader("../../gdx/libs/gdx-natives.jar").load("gdx");\r
 \r
-               GdxTest test = new ShaderCollectionTest();\r
+               GdxTest test = new NetAPITest();\r
                LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();\r
                config.useGL20 = test.needsGL20();\r
                config.width = 1024;\r
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 (file)
index 0000000..b33913a
--- /dev/null
@@ -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 (file)
index 0000000..824c00c
--- /dev/null
@@ -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 (file)
index 0000000..56ac5db
--- /dev/null
@@ -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