Sign In Register

How can we help you today?

Start a new topic
Answered

Not able to connect to GameSpark SDK in android

Hi,


I was trying to login using facebook but when i call 

 Map<String, Object> result = gamesparksdk.facebookConnectRequest(

                                                        session.getAccessToken(),"").send();


Sometimes I get a response


error=GameSparks SDK not ready to send. SDK state: CONNECTING_TO_LOADBALANCER


but sometimes it work. and i get a correct response.

I am calling the gamespark.initialise and  gamesspark.connect() in the onCreate() of the activity.

Can someone please tell me what am i doing wrong.


Thanks 

Shubham


Best Answer
Well , The problem was because of Secrets.GAMESPARKS_SERVICE_URL variable , It was wrong.I checked again.It must be wss://preview.gamesparks.net/ws/GAMESPARKS_API_KEY that can be found in Test Harness.I have another problem now.I think I must open a ticket.
Shubham Dhabhai , I hope your problem get solved.

I've been trying to recreate this problem but to no avail. Could you possibly post your onCreate() code to the forum? I did have a wobbly internet connection at one point but GameSparks just waited on "connect" until the network came back up.


Shane.

Hi Shane,


 // initializing gamespark sdk and connecting it to the gamespark service.

        GameSparksAndroidApi.initialise(GAMESPARKS_SERVICES_URL,GAMESPARKS_API_SECRET, getApplication());

        GameSparksAndroidApi gs = GameSparksAndroidApi.getInstance();

        gs.connect();


I am doing this in onCreate() of main activity and I am still facing the same issue. I am using android studio 0.8.11 and Mac OS X 10.9.4 if it is of any help.


Shubham

Hmm, I did mine in Eclipse in the same version of OS X, but that shouldn't make much of a difference...


Here's my code:


   

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        //Start GameSparks First
        GameSparksAndroidApi.initialise(GAMESPARKS_SERVICE_URL, GAMESPARKS_API_SECRET, getApplication());
        gamesparksApi = GameSparksAndroidApi.getInstance();
        gamesparksApi.setMessageRecievedListener(this);
        
		//Facebook stuff goes here

}

@Override
    public void onMessage(Map<String, Object> message){
    	//Handle the server message here
    }
        

   

Try that and if it doesn't work I'll bring the project into Android Studio and see how it goes.


Edit:

 I should also add that I call   

Map<String, Object> response1 = gamesparksApi.facebookConnectRequest(session.getAccessToken(), null).send();

  

in the OnComplete() after logging into Facebook


  

        				//Callback after Graph API response with user object
						@Override
						public void onCompleted(GraphUser user, Response response) {
							if(user != null){
								TextView welcome = (TextView) findViewById(R.id.welcome);
								welcome.setText("Hello " + user.getName() + "!");
								
								//Add GameSparks Facebook connect request here
								Map<String, Object> response1 = gamesparksApi.facebookConnectRequest(session.getAccessToken(), null).send();
							}
							
						}

   


Shane.

Hi Shane,


The difference between your approach and mine approach is just adding message listener and that should not make any difference. But still I tried that and it is giving the same result.

Also I am calling facebookConnectRequest in onSessionStateChange() which is a call back whenever state of session is changed. So I think that is also not a problem as the problem is not with facebook but with gamesparks.(error=GameSparks SDK not ready to send. SDK state: CONNECTING_TO_LOADBALANCER ). 


But if you want I can try that approach.


I think the GameSpark sdk is taking time to initialise and that is happening on a separate thread. But I am not sure. Can you please have a look at it.


Shubham


Hi Shane, 

I tried the program given by you and after debugging it , the response of facebookConnecRequest is 

error = GameSparks SDK not ready to send. SDK state:STOPPED


sometimes it is error = GamesSparks SDK not ready to send. SDK state : CONNECTING TO SERVICE

Hi Shane 

I am pasting the log file of my project may be that may be of some help.


10-15 16:46:42.548 14509-14509/com.moldedbits.liarpoker D/dalvikvm﹕ Late-enabling CheckJNI

10-15 16:46:42.628 14509-14509/com.moldedbits.liarpoker W/ActivityThread﹕ Application com.moldedbits.liarpoker is waiting for the debugger on port 8100...

10-15 16:46:42.631 14509-14509/com.moldedbits.liarpoker I/System.out﹕ Sending WAIT chunk

10-15 16:46:42.664 14509-14516/com.moldedbits.liarpoker I/dalvikvm﹕ Debugger is active

10-15 16:46:42.833 14509-14509/com.moldedbits.liarpoker I/System.out﹕ Debugger has connected

10-15 16:46:42.833 14509-14509/com.moldedbits.liarpoker I/System.out﹕ waiting for debugger to settle...

10-15 16:46:43.033 14509-14509/com.moldedbits.liarpoker I/System.out﹕ waiting for debugger to settle...

10-15 16:46:43.234 14509-14509/com.moldedbits.liarpoker I/System.out﹕ waiting for debugger to settle...

10-15 16:46:43.434 14509-14509/com.moldedbits.liarpoker I/System.out﹕ waiting for debugger to settle...

10-15 16:46:43.634 14509-14509/com.moldedbits.liarpoker I/System.out﹕ waiting for debugger to settle...

10-15 16:46:43.835 14509-14509/com.moldedbits.liarpoker I/System.out﹕ waiting for debugger to settle...

10-15 16:46:44.035 14509-14509/com.moldedbits.liarpoker I/System.out﹕ waiting for debugger to settle...

10-15 16:46:44.235 14509-14509/com.moldedbits.liarpoker I/System.out﹕ waiting for debugger to settle...

10-15 16:46:44.436 14509-14509/com.moldedbits.liarpoker I/System.out﹕ waiting for debugger to settle...

10-15 16:46:44.637 14509-14509/com.moldedbits.liarpoker I/System.out﹕ debugger has settled (1462)

10-15 16:46:44.979 14509-14509/com.moldedbits.liarpoker D/GameSparks SDK﹕ connect

10-15 16:46:44.992 14509-14509/com.moldedbits.liarpoker D/GameSparks SDK﹕ New state: CONNECTING_TO_LOADBALANCER

10-15 16:46:49.993 14509-14509/com.moldedbits.liarpoker E/GameSparks SDK﹕ Timeout waiting to connect

10-15 16:46:49.994 14509-14509/com.moldedbits.liarpoker D/GameSparks SDK﹕ New state: STOPPED

10-15 16:46:50.002 14509-14534/com.moldedbits.liarpoker D/GameSparks SDK﹕ mSocket closed in disconnect

10-15 16:46:50.164 14509-14509/com.moldedbits.liarpoker D/GameSparks SDK﹕ onConnectivityChange, network is available

10-15 16:46:50.169 14509-14509/com.moldedbits.liarpoker D/GameSparks SDK﹕ New state: CONNECTING_TO_LOADBALANCER

10-15 16:46:50.240 14509-14509/com.moldedbits.liarpoker I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LNX.LA.3.5.1_RB1.04.04.02.048.018_msm8610_LNX.LA.3.5.1_RB1__release_AU ()

    OpenGL ES Shader Compiler Version: E031.24.00.08

    Build Date: 03/07/14 Fri

    Local Branch:

    Remote Branch: quic/LNX.LA.3.5.1_RB1.1

    Local Patches: NONE

    Reconstruct Branch: AU_LINUX_ANDROID_LNX.LA.3.5.1_RB1.04.04.02.048.018 + f2fd134 + NOTHING

10-15 16:46:50.275 14509-14509/com.moldedbits.liarpoker D/OpenGLRenderer﹕ Enabling debug mode 0

10-15 16:46:52.566 14509-14534/com.moldedbits.liarpoker D/GameSparks SDK﹕ stopThreads

10-15 16:46:52.576 14509-14535/com.moldedbits.liarpoker D/GameSparks SDK﹕ Socket is closed

    java.net.SocketException: Socket is closed

            at com.android.org.conscrypt.OpenSSLSocketImpl.checkOpen(OpenSSLSocketImpl.java:238)

            at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:251)

            at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.<init>(OpenSSLSocketImpl.java:661)

            at com.android.org.conscrypt.OpenSSLSocketImpl.getInputStream(OpenSSLSocketImpl.java:632)

            at com.gamesparks.client.android.websocket.WebSocketClient$1.run(WebSocketClient.java:116)

            at java.lang.Thread.run(Thread.java:841)

10-15 16:46:52.582 14509-14535/com.moldedbits.liarpoker D/GameSparks SDK﹕ New state: STOPPED

10-15 16:46:52.582 14509-14535/com.moldedbits.liarpoker D/GameSparks SDK﹕ mThread has stopped

10-15 16:46:52.583 14509-14535/com.moldedbits.liarpoker D/GameSparks SDK﹕ mSocket closed in finally block

10-15 16:46:52.584 14509-14558/com.moldedbits.liarpoker D/GameSparks SDK﹕ mSocket closed in disconnect

10-15 16:46:52.588 14509-14558/com.moldedbits.liarpoker D/GameSparks SDK﹕ stopThreads

10-15 16:46:52.591 14509-14559/com.moldedbits.liarpoker D/GameSparks SDK﹕ mThread has stopped

10-15 16:46:52.591 14509-14559/com.moldedbits.liarpoker D/GameSparks SDK﹕ mSocket closed in finally block

10-15 16:47:05.212 14509-14509/com.moldedbits.liarpoker I/LoginFragment﹕ Logged in...

10-15 16:47:43.366 14509-14549/com.moldedbits.liarpoker D/GameSparks SDK﹕ In stopped state but network is available so attempting connect...

10-15 16:47:43.366 14509-14549/com.moldedbits.liarpoker D/GameSparks SDK﹕ connect

10-15 16:47:43.391 14509-14549/com.moldedbits.liarpoker D/GameSparks SDK﹕ New state: CONNECTING_TO_LOADBALANCER

10-15 16:47:43.582 14509-14509/com.moldedbits.liarpoker I/Choreographer﹕ Skipped 2307 frames! The application may be doing too much work on its main thread.

10-15 16:47:46.516 14509-14612/com.moldedbits.liarpoker D/GameSparks SDK﹕ WebSocket connected

10-15 16:47:46.525 14509-14611/com.moldedbits.liarpoker D/GameSparks SDK﹕ mSocket closed in disconnect

10-15 16:47:46.527 14509-14611/com.moldedbits.liarpoker D/GameSparks SDK﹕ stopThreads

10-15 16:47:46.533 14509-14612/com.moldedbits.liarpoker D/GameSparks SDK﹕ New state: CONNECTING_TO_SERVICE

10-15 16:47:46.534 14509-14612/com.moldedbits.liarpoker D/GameSparks SDK﹕ HybiParser has stopped

10-15 16:47:46.534 14509-14612/com.moldedbits.liarpoker D/GameSparks SDK﹕ mThread has stopped

10-15 16:47:46.534 14509-14612/com.moldedbits.liarpoker D/GameSparks SDK﹕ mSocket closed in finally block

10-15 16:47:48.396 14509-14549/com.moldedbits.liarpoker E/GameSparks SDK﹕ Timeout waiting to connect

10-15 16:47:48.397 14509-14549/com.moldedbits.liarpoker D/GameSparks SDK﹕ New state: STOPPED

10-15 16:47:48.407 14509-14633/com.moldedbits.liarpoker D/GameSparks SDK﹕ mSocket closed in disconnect

Å10-15 16:47:49.952 14509-14633/com.moldedbits.liarpoker D/GameSparks SDK﹕ stopThreads

10-15 16:47:49.956 14509-14634/com.moldedbits.liarpoker D/GameSparks SDK﹕ mThread has stopped

10-15 16:47:49.965 14509-14634/com.moldedbits.liarpoker D/GameSparks SDK﹕ mSocket closed in finally block


Please have a look into this as I am not able to work because of this issue.


Thanks

Shubham

Well , I have the same problem.

 

New state: CONNECTING_TO_LOADBALANCER
08-20 07:42:30.102: D/GameSparks SDK(13146): at com.gamesparks.client.android.websocket.WebSocketClient$1.run(WebSocketClient.java:87)

New state: STOPPED

 


I guess my problem is that getScheme() in WebSocketClient.java file returns null



 

int port = (mURI.getPort() != -1) ? mURI.getPort() : (mURI.getScheme().equals("wss") ? 443 : 80);

 

here is the my mainactivity code:


 

	private GameSparksAndroidApi gamesparksApi;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		GameSparksAndroidApi.initialise(Secrets.GAMESPARKS_SERVICE_URL,
				Secrets.GAMESPARKS_API_SECRET, getApplication());
		gamesparksApi = GameSparksAndroidApi.getInstance();
		gamesparksApi.setMessageRecievedListener(this);
		gamesparksApi.setSdkConnectedListener(this);
		gamesparksApi.connect();

		

		AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();

		initialize(new RacingGame(), cfg);
	}

	@Override
	public void onMessage(Map<String, Object> message) {
		message.isEmpty();

	}

	@Override
	protected void onPause() {
		super.onPause();
		gamesparksApi.onPause();
	}

	@Override
	protected void onResume() {
		super.onResume();
		gamesparksApi.onResume();
	}

	@Override
	public void onConnected() {
		gamesparksApi.findMatchRequest(null, null, "match_normal", null)
				.sendBackground(new GSListener() {

					@Override
					public void onMessage(Map<String, Object> responseData) {
						responseData.isEmpty();

					}

				});

	}

 



Answer
Well , The problem was because of Secrets.GAMESPARKS_SERVICE_URL variable , It was wrong.I checked again.It must be wss://preview.gamesparks.net/ws/GAMESPARKS_API_KEY that can be found in Test Harness.I have another problem now.I think I must open a ticket.
Shubham Dhabhai , I hope your problem get solved.
Login to post a comment