i get connection error use WrapClient.connectWithUserName(name, string) full code attach in below

0 votes
package com.shephertzdemo.activity;
 
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
 
import com.shephertz.app42.gaming.multiplayer.client.WarpClient;
import com.shephertz.app42.gaming.multiplayer.client.command.WarpResponseResultCode;
import com.shephertz.app42.gaming.multiplayer.client.events.ConnectEvent;
import com.shephertz.app42.gaming.multiplayer.client.listener.ConnectionRequestListener;
import com.shephertzdemo.R;
import com.shephertzdemo.utils.Constant;
import com.shephertzdemo.utils.Utils;
 
public class MainActivity extends Activity implements ConnectionRequestListener {
private WarpClient theClient;
EditText et_username;
private String authData = "";
public ProgressDialog progressDialog;
LinearLayout layoutLogin, loyoutRoom;
 
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
layoutLogin = (LinearLayout) findViewById(R.id.linearLayout1);
loyoutRoom = (LinearLayout) findViewById(R.id.linearLayout2);
layoutLogin.setVisibility(View.VISIBLE);
et_username = (EditText) findViewById(R.id.nameEditText);
init();
}
 
private void init() {
Log.d("init", "init-start");
try {
Log.d("init", "init-try");
WarpClient.initialize(Constant.APP_KEY, Constant.HOST_NAME);
WarpClient.setRecoveryAllowance(Constant.MAX_RECOVERY_ATTEMPT);
theClient = WarpClient.getInstance();
} catch (Exception e) {
Log.d("init", "init-catch");
e.printStackTrace();
Utils.showToastAlert(this, Constant.ALERT_INIT_EXEC);
}
Log.d("init", "init-end");
 
}
 
public void onPlayGameClicked(View v) {
Log.d("onclick", "Play button click");
if (et_username.getText().length() == 0) {
Utils.showToastAlert(this,
getApplicationContext().getString(R.string.enterName));
return;
}
String userName = et_username.getText().toString().trim();
loginToAppWarp(userName, "");
}
 
private void loginToAppWarp(String name, String string) {
Log.d("loginToAppWarp", "loginToAppWarp");
Log.d("loginToAppWarp", "" + name);
Utils.userName = name;
theClient.connectWithUserName(name, string);
progressDialog = ProgressDialog.show(this, "", "Connecting...");
progressDialog.setCancelable(true);
}
 
@Override
public void onStart() {
super.onStart();
theClient.addConnectionRequestListener(this);
}
 
@Override
public void onStop() {
super.onStop();
theClient.removeConnectionRequestListener(this);
}
 
@Override
public void onConnectDone(final ConnectEvent event, String desc) {
Log.d("onConnectDone", "onConnectDone");
Log.d("onConnectDone", event.getResult() + " listener " + desc);
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.d("run", "run");
if (progressDialog != null) {
progressDialog.dismiss();
progressDialog = null;
}
Log.d("result ", String.valueOf(event.getResult()));
Log.d("sucess ", String.valueOf(WarpResponseResultCode.SUCCESS));
Log.d("bad request ", String.valueOf(WarpResponseResultCode.BAD_REQUEST));
Log.d("auth error ", String.valueOf(WarpResponseResultCode.AUTH_ERROR));
Log.d("connection error ", String.valueOf(WarpResponseResultCode.CONNECTION_ERROR));
Log.d("resurce not found ", String.valueOf(WarpResponseResultCode.RESOURCE_NOT_FOUND));
Log.d("conn error recoverable", String.valueOf(WarpResponseResultCode.CONNECTION_ERROR_RECOVERABLE));
Log.d("resource move ", String.valueOf(WarpResponseResultCode.RESOURCE_MOVED));
Log.d("result size error ", String.valueOf(WarpResponseResultCode.RESULT_SIZE_ERROR));
Log.d("sucess recoverd ", String.valueOf(WarpResponseResultCode.SUCCESS_RECOVERED));
Log.d("unknown error ", String.valueOf(WarpResponseResultCode.UNKNOWN_ERROR));
 
if (event.getResult() == WarpResponseResultCode.SUCCESS) {
Log.d("success", "success");
goToRoomList();
} else if (event.getResult() == WarpResponseResultCode.BAD_REQUEST) {
Log.d("bad requset", "bad request");
theClient.disconnect();
} else {
Log.d("else", "else");
Utils.showToastAlert(MainActivity.this,
Constant.ALERT_CONN_FAIL + event.getResult());
}
}
});
}
 
@Override
public void onDisconnectDone(ConnectEvent event) {
if (event.getResult() == WarpResponseResultCode.SUCCESS) {
 
} else {
Utils.showToastAlertOnUIThread(MainActivity.this,
Constant.ALERT_ERR_DISCONN);
}
}
 
@Override
public void onInitUDPDone(byte arg0) {
 
}
 
protected void goToRoomList() {
loyoutRoom.setVisibility(View.VISIBLE);
layoutLogin.setVisibility(View.GONE);
}
}
 
 
thanks in advance
 
asked Dec 22, 2014 in AppWarpS2 by deepakjain.mobifly (10 points)
use local host for admin dashboard and pass my ip in hostname

1 Answer

0 votes

Hi Deepak,

You need to run server and your android application on same network. If you are testing Android Application by running it on 3G/2G network it will not work.
 
You need to first run your server application on your PC that is connected to a Wifi Network. Then run your android application on mobile by connecting to the same Wifi network. Remember you should use the IP address in android application that has been assigned by your network to the machine running the server.
 
This has to be done only for testing. Once your app is ready and deployed on public servers, you will not need to do the above scenario instead just use the public IP address and it will work on 3G/2G networks too.
 
Thanks
answered Dec 22, 2014 by Suyash Mohan (900 points)
You will need to create two projects. First you need to create a server application. You will need to use AppWarp S2 libs. Once you have done that you will need to create your Android project which will use the Android SDK. Are you mixing the server side code with client side code. Both require different sdks. Server side work independent of client side i.e. even though you write code in java on server side you will be able to connect to it through all platforms.
Can i use your QuizUp server side code in android app?
What do you mean by using server side code in android app?
Server side code can not be mixed with client side code in your case Android code.

But you can do use the same server for your Android App.

In Simpler words you can connect to same server from your android app. But if you are using code from the server in your android app, it will not work
no sir,i just make a java project and import Quizup Server code on it, its a separate project,and use your dashboard admin  in my pc local host and run ant -f warp.xml then your server side code work and dashboard work on local host. and i make one android project use app key . so i just want to say same this way use quizup code in app i am right or not
Yes! It will work. Server works independently. It does not matter whether you are using it with Android, Windows Phone or iOS
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...