我正在开发一个Android聊天应用程序。我无法使用Android中的Socket.Io客户端连接到我的服务器。
1.ChatActivity.java
public class ChatActivity extends Activity {
EditText edMessage;
private Socket mSocket;
{
try {
mSocket = IO.socket(Constants.CHAT_SERVER_URL);
Log.e("Socket", String.valueOf(mSocket));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat);
edMessage = (EditText) findViewById(R.id.edtMessage);
String message = edMessage.getText().toString().trim();
mSocket.connect();
// mSocket.emit("subscribe", "Testing");
mSocket.on("subscribe", subscribe);
}
private Emitter.Listener subscribe = new Emitter.Listener() {
@Override
public void call(final Object... args) {
runOnUiThread(new Runnable() {
@Override
public void run() {
String room = (String) args[0];
Log.e("Response", room);
}
});
}
};
}
请帮我解决问题。我无法验证服务器是否已连接。