WebSocket Connection for xmpp - java

I am trying to establish a websocket connection with port:5280,but unable to connect(server is not listening).
public static WebSocketClient cc;
public static void main(String[] args) throws URISyntaxException
{
cc=new WebSocketClient(new URI("ws://localhost:5280"))
{
#Override
public void onOpen(ServerHandshake arg0)
{
// TODO Auto-generated method stub
System.out.println("onOpen" +arg0);
}
#Override
public void onMessage(String arg0)
{
// TODO Auto-generated method stub
System.out.println("onMessage");
}
#Override
public void onError(Exception arg0)
{
// TODO Auto-generated method stub
System.out.println("onError");
}
#Override
public void onClose(int arg0, String arg1, boolean arg2)
{
// TODO Auto-generated method stub
System.out.println("onClose");
}
};
cc.connect();
Above one is working with new URI("ws://localhost:8887/8080/5120") but having some problem with port no-5280.
Give me any Fix??

Related

Java Settings Menu

I am curently working on a GUI and when clicking a certain button:
settingsB.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
System.out.println("Settings");
}
});
Instead of just printing it there should a new window open where you can adjust settings with sliders textboxes, ... How would you approach that? With new classes or all inside the action listener?
Edit:
My "current solution" is based on the great suggestion from user Holger to call a method showSettingsDialogue():
private void showSettingsDialogue() {
if(settingsOpen) {
return;
}
else {
settingsOpen = true;
settingWindow = new SettingsWindow();
settingWindow.addWindowListener(new WindowListener() {
#Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
#Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
#Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
#Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
#Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
}
#Override
public void windowClosed(WindowEvent e) {
settingsOpen = false;
}
#Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
});
}
Unfortunally with this way I have to write down even unimplemented methods. Any bether solution then this?

subscribeOn has no effect when creating new Observables [duplicate]

I am using rxjava in eclipse. I cretaed the below posted example.
the issue is,, when i run the code, I receive only
onSubscribe: 0
and I dont receive any output from onNext.
please let me know why I do not receive any output from onNext, and how to fix it
code:
public static void main(String[] args) {
Observable<String> stringObservable = Observable.just("Hello from just Operator1");
stringObservable
.subscribeOn(Schedulers.newThread())
.observeOn(Schedulers.io())
.subscribe(new Observer<Object>() {
#Override
public void onComplete() {
// TODO Auto-generated method stub
System.out.println("onComplete: OK");
}
#Override
public void onError(Throwable arg0) {
// TODO Auto-generated method stub
}
#Override
public void onNext(Object arg0) {
// TODO Auto-generated method stub
System.out.println("onNext: " + (String) arg0);
}
#Override
public void onSubscribe(Disposable arg0) {
// TODO Auto-generated method stub
System.out.println("onSubscribe: " + arg0);
}
});
}

GamesStatusCodes, Status 6, STATUS_NETWORK_ERROR_OPERATION_FAILED

Hello guys,
I have been trying to implement google play services with LibGDX and am trying to create a Quickgame() where everyone is auto matched. However, on the public void onRoomCreated(int arg0, Room arg1) method, the when i print out the status code, it keeps giving me 6.
I have tried several solutions but to no avail
Relinking the game and ensuring the SHA1 code is correct. (Sign in works correctly)
Checking my phones network status, it is connected to the internet.
Does anyone perhaps have a solution? Thank you!
public class GSGameHelper extends GameHelper implements RoomUpdateListener, RealTimeMessageReceivedListener,RoomStatusUpdateListener {
final static String TAG = "ButtonClicker2000";
static final int RC_SELECT_PLAYERS = 10000;
static final int RC_WAITING_ROOM = 10002;
private Activity activity;
private String mRoomID;
private MacroHardv2 game;
public GSGameHelper(Activity activity, int clientsToUse) {
super(activity, clientsToUse);
this.activity = activity;
// TODO Auto-generated constructor stub
}
public void quickGame(){
Bundle am = RoomConfig.createAutoMatchCriteria(1, 1, 0);
RoomConfig.Builder roomConfigBuilder = makeBasicRoomConfigBuilder();
roomConfigBuilder.setAutoMatchCriteria(am);
RoomConfig roomConfig = roomConfigBuilder.build();
Games.RealTimeMultiplayer.create(getApiClient(), roomConfig);
// prevent screen from sleeping during handshake
//getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
public void initMatch(){
Intent intent = Games.RealTimeMultiplayer.getSelectOpponentsIntent(getApiClient(), 1, 1);
this.activity.startActivityForResult(intent, RC_SELECT_PLAYERS);
}
private RoomConfig.Builder makeBasicRoomConfigBuilder() {
return RoomConfig.builder((RoomUpdateListener) this)
.setMessageReceivedListener((RealTimeMessageReceivedListener) this)
.setRoomStatusUpdateListener((RoomStatusUpdateListener) this);
}
public void onActivityResult(int request,int response, Intent data){
if (request == GSGameHelper.RC_WAITING_ROOM){
if (response == Activity.RESULT_CANCELED || response == GamesActivityResultCodes.RESULT_LEFT_ROOM ){
Games.RealTimeMultiplayer.leave(getApiClient(), this, mRoomID);
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
BaseGameUtils.showAlert(activity, "Partida abandonada");
}else{
BaseGameUtils.showAlert(activity, "Comenzando partida");
this.game.multiplayerGameReady();
}
}
else if (request == GSGameHelper.RC_SELECT_PLAYERS){
if (response != Activity.RESULT_OK) {
// user canceled
return;
}
// get the invitee list
Bundle extras = data.getExtras();
final ArrayList<String> invitees =
data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);
// get auto-match criteria
Bundle autoMatchCriteria = null;
int minAutoMatchPlayers =
data.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0);
int maxAutoMatchPlayers =
data.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0);
Gdx.app.log("J", "Jmin" + minAutoMatchPlayers + " Jmax:" + maxAutoMatchPlayers);
for (String invitee : invitees){
Gdx.app.log("L" , invitee);
}
if (minAutoMatchPlayers > 0) {
autoMatchCriteria = RoomConfig.createAutoMatchCriteria(
minAutoMatchPlayers, maxAutoMatchPlayers, 0);
} else {
autoMatchCriteria = null;
}
// create the room and specify a variant if appropriate
RoomConfig.Builder roomConfigBuilder = makeBasicRoomConfigBuilder();
roomConfigBuilder.addPlayersToInvite(invitees);
if (autoMatchCriteria != null) {
roomConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
}
RoomConfig roomConfig = roomConfigBuilder.build();
Games.RealTimeMultiplayer.create(getApiClient(), roomConfig);
// prevent screen from sleeping during handshake
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}else{
super.onActivityResult(request, response, data);
}
}
#Override
public void onJoinedRoom(int arg0, Room arg1) {
if (arg0 != GamesStatusCodes.STATUS_OK) {
Gdx.app.log("R", "Joined FAILED");
}else{
Gdx.app.log("R", "Joined Room");
}
}
#Override
public void onLeftRoom(int arg0, String arg1) {
BaseGameUtils.makeSimpleDialog(activity, "Abandonado partida");
Gdx.app.log("LEAVE", "Me fui de la Room");
}
#Override
public void onRoomConnected(int arg0, Room arg1) {
// TODO Auto-generated method stub
}
public void setGame(MacroHardv2 game){
this.game = game;
}
#Override
public void onRoomCreated(int arg0, Room arg1) {
if (arg0 != GamesStatusCodes.STATUS_OK) {
//BaseGameUtils.showAlert(activity, "Room creation error");
BaseGameUtils.makeSimpleDialog(activity, "Error al crear la partida", "Room creation error " + arg0).show();
Gdx.app.log("R", "Room Created FAILED");
}else{
Gdx.app.log("R", "Room Created");
mRoomID = arg1.getRoomId();
Intent i = Games.RealTimeMultiplayer.getWaitingRoomIntent(getApiClient(), arg1, 2);
this.activity.startActivityForResult(i, RC_WAITING_ROOM);
}
}
public void sendPos(float x,float y){
try{
byte[] mensaje;
mensaje = ByteBuffer.allocate(8).putFloat(x).putFloat(y).array();
Games.RealTimeMultiplayer.sendUnreliableMessageToOthers(getApiClient(), mensaje, mRoomID);
}catch(Exception e){
}
}
#Override
public void onRealTimeMessageReceived(RealTimeMessage rtm) {
float x, y;
byte[] b = rtm.getMessageData();
ByteBuffer bf = ByteBuffer.wrap(b);
x = bf.getFloat();
y = bf.getFloat();
game.updateGameWorld(x,y);
}
#Override
public void onConnectedToRoom(Room arg0) {
// TODO Auto-generated method stub
}
#Override
public void onDisconnectedFromRoom(Room arg0) {
// TODO Auto-generated method stub
}
#Override
public void onP2PConnected(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void onP2PDisconnected(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void onPeerDeclined(Room arg0, List<String> arg1) {
// TODO Auto-generated method stub
}
#Override
public void onPeerInvitedToRoom(Room arg0, List<String> arg1) {
// TODO Auto-generated method stub
}
#Override
public void onPeerJoined(Room arg0, List<String> arg1) {
// TODO Auto-generated method stub
}
#Override
public void onPeerLeft(Room arg0, List<String> arg1) {
// TODO Auto-generated method stub
}
#Override
public void onPeersConnected(Room arg0, List<String> arg1) {
// TODO Auto-generated method stub
}
#Override
public void onPeersDisconnected(Room arg0, List<String> arg1) {
// TODO Auto-generated method stub
}
#Override
public void onRoomAutoMatching(Room arg0) {
// TODO Auto-generated method stub
}
#Override
public void onRoomConnecting(Room arg0) {
// TODO Auto-generated method stub
}
}
Based on this documentation, you need to check if multiplayer support is enabled for your client ID. You need to enable real-time multiplayer support in the Developer Console. Check this link on how to enable multiplayer support.
This SO ticket might also help.

how can understand that the DJ native swing jwebbrowser has been completely load the web page?

I want to execute my javascript code in DJ native swing jwebbrowser, but I should wait for the page loading, how can I set listener for it?
I try the following, but after loading it always run the script also it operate late!
webBrowser.addWebBrowserListener(new WebBrowserListener(){
#Override
public void commandReceived(WebBrowserCommandEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void loadingProgressChanged(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void locationChangeCanceled(WebBrowserNavigationEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void locationChanged(WebBrowserNavigationEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void locationChanging(WebBrowserNavigationEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void statusChanged(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
if(webBrowser.getLoadingProgress() == 100)
webBrowser.executeJavascript("some js code");");
}
#Override
public void titleChanged(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void windowClosing(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
frame.dispose();
}
#Override
public void windowOpening(WebBrowserWindowOpeningEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void windowWillOpen(WebBrowserWindowWillOpenEvent arg0) {
// TODO Auto-generated method stub
}
});
what should i do?
I should override loadingProgressChanged(WebBrowserEvent arg0) not statusChanged(WebBrowserEvent arg0)
#Override
public void loadingProgressChanged(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
if(webBrowser.getLoadingProgress() == 100)
webBrowser.executeJavascript("some js code");
}
but still it takes time to load my html!

Slick2d State Transition Error

I followed a tutorial to make my first slick2d game, unfortunately a problem appears when transition from the play ground state to the menu state.
I tried many things but I didn't recognize the problem
this is the main class (GAME)
package javagame;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class Game extends StateBasedGame {
public static final String gamename = "Ham Blaster";
public static final int menu = 0;
public static final int play = 1;
public Game(String gamename)
{
super(gamename);
this.addState(new Menu(menu));
this.addState(new Play(menu));
this.addState(new Play(play));
this.addState(new Menu(play));
}
public void initsStatesList(GameContainer gc) throws SlickException
{
this.getState(menu).init(gc, this);
this.getState(play).init(gc, this);
this.enterState(menu);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
AppGameContainer appgc;
try {
appgc = new AppGameContainer(new Game(gamename));
appgc.setDisplayMode(640,360,false);
appgc.start();
}
catch(SlickException e)
{
e.printStackTrace();
}
}
public void initStatesList(GameContainer arg0) throws SlickException {
// TODO Auto-generated method stub
}
}
The Menu Class
package javagame;
import org.lwjgl.input.Mouse;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.*;
public class Menu extends BasicGameState implements GameState {
private int state;
Image playNow;
Image exitGame;
public Menu(int menu) {
// TODO Auto-generated constructor stub
}
public void init(GameContainer arg0, StateBasedGame arg1)
throws SlickException {
}
public void render(GameContainer arg0, StateBasedGame arg1, Graphics g)
throws SlickException {
// TODO Auto-generated method stub
playNow = new Image("res/playNow.png");
exitGame=new Image("res/exitGame.png");
g.drawString("Welcome to BuckyLand", 100, 50);
g.drawImage(playNow, 100, 100);
g.drawImage(exitGame, 100, 200);
}
public void update(GameContainer gc, StateBasedGame sbg, int arg2)
throws SlickException {
int posX = Mouse.getX();
int posY = Mouse.getY();
if (posX > 100 && posX < 100+playNow.getWidth() && posY > 209 &&posY<260)
{
if (Mouse.isButtonDown(0)) {
sbg.enterState(1);
}
}
if (posX > 100 && posX < 100+playNow.getWidth() && posY > 109 &&posY<160)
{
if (Mouse.isButtonDown(0)) {
System.exit(0);
}
}
}
public void mouseClicked(int arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
public void mouseDragged(int arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
public void mouseMoved(int arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
public void mousePressed(int arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
public void mouseReleased(int arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
public void mouseWheelMoved(int arg0) {
// TODO Auto-generated method stub
}
public void inputEnded() {
// TODO Auto-generated method stub
}
public void inputStarted() {
// TODO Auto-generated method stub
}
public boolean isAcceptingInput() {
// TODO Auto-generated method stub
return false;
}
public void setInput(Input arg0) {
// TODO Auto-generated method stub
}
public void keyPressed(int arg0, char arg1) {
// TODO Auto-generated method stub
}
public void keyReleased(int arg0, char arg1) {
// TODO Auto-generated method stub
}
public void controllerButtonPressed(int arg0, int arg1) {
// TODO Auto-generated method stub
}
public void controllerButtonReleased(int arg0, int arg1) {
// TODO Auto-generated method stub
}
public void controllerDownPressed(int arg0) {
// TODO Auto-generated method stub
}
public void controllerDownReleased(int arg0) {
// TODO Auto-generated method stub
}
public void controllerLeftPressed(int arg0) {
// TODO Auto-generated method stub
}
public void controllerLeftReleased(int arg0) {
// TODO Auto-generated method stub
}
public void controllerRightPressed(int arg0) {
// TODO Auto-generated method stub
}
public void controllerRightReleased(int arg0) {
// TODO Auto-generated method stub
}
public void controllerUpPressed(int arg0) {
// TODO Auto-generated method stub
}
public void controllerUpReleased(int arg0) {
// TODO Auto-generated method stub
}
public void enter(GameContainer arg0, StateBasedGame arg1)
throws SlickException {
// TODO Auto-generated method stub
}
public int getID() {
// TODO Auto-generated method stub
return 0;
}
public void leave(GameContainer arg0, StateBasedGame arg1)
throws SlickException {
// TODO Auto-generated method stub
}
}
The Play Class
package javagame;
import org.newdawn.slick.Animation;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.*;
public class Play extends BasicGameState {
Animation bucky,movingUp,movingDown,movingLeft,movingRight;
Image worldMap;
boolean quit = false;
int[] duration={200,200};
float buckyPosX = 0;
float buckyPosY = 0;
float shiftX = buckyPosX + 320;
float shiftY = buckyPosY + 160;
public Play(int play) {
// TODO Auto-generated constructor stub
}
public void mouseClicked(int arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
public void mouseDragged(int arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
public void mouseMoved(int arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
public void mousePressed(int arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
public void mouseReleased(int arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
public void mouseWheelMoved(int arg0) {
// TODO Auto-generated method stub
}
public void inputEnded() {
// TODO Auto-generated method stub
}
public void inputStarted() {
// TODO Auto-generated method stub
}
public boolean isAcceptingInput() {
// TODO Auto-generated method stub
return false;
}
public void setInput(Input arg0) {
// TODO Auto-generated method stub
}
public void keyPressed(int arg0, char arg1) {
// TODO Auto-generated method stub
}
public void keyReleased(int arg0, char arg1) {
// TODO Auto-generated method stub
}
public void controllerButtonPressed(int arg0, int arg1) {
// TODO Auto-generated method stub
}
public void controllerButtonReleased(int arg0, int arg1) {
// TODO Auto-generated method stub
}
public void controllerDownPressed(int arg0) {
// TODO Auto-generated method stub
}
public void controllerDownReleased(int arg0) {
// TODO Auto-generated method stub
}
public void controllerLeftPressed(int arg0) {
// TODO Auto-generated method stub
}
public void controllerLeftReleased(int arg0) {
// TODO Auto-generated method stub
}
public void controllerRightPressed(int arg0) {
// TODO Auto-generated method stub
}
public void controllerRightReleased(int arg0) {
// TODO Auto-generated method stub
}
public void controllerUpPressed(int arg0) {
// TODO Auto-generated method stub
}
public void controllerUpReleased(int arg0) {
// TODO Auto-generated method stub
}
public void enter(GameContainer arg0, StateBasedGame arg1)
throws SlickException {
// TODO Auto-generated method stub
}
public int getID() {
// TODO Auto-generated method stub
return 1;
}
public void init(GameContainer arg0, StateBasedGame sbg)
throws SlickException {
// TODO Auto-generated method stub
worldMap = new Image("res/world.png");
Image[] walkUp = {new Image("/res/buckysBack.png"),new
Image("res/buckysBack.png")};
Image[] walkDown = {new Image("/res/buckysFront.png"),new
Image("res/buckysFront.png")};
Image[] walkLeft = {new Image("/res/buckysLeft.png"),new
Image("res/buckysLeft.png")};
Image[] walkRight = {new Image("/res/buckysRight.png"),new
Image("res/buckysRight.png")};
movingUp = new Animation(walkUp,duration,false);
movingDown = new Animation(walkDown,duration,false);
movingLeft = new Animation(walkLeft,duration,false);
movingRight = new Animation(walkRight,duration,false);
bucky = movingDown;
}
public void leave(GameContainer arg0, StateBasedGame arg1)
throws SlickException {
// TODO Auto-generated method stub
}
public void render(GameContainer arg0, StateBasedGame arg1, Graphics g)
throws SlickException {
// TODO Auto-generated method stub
worldMap.draw(buckyPosX,buckyPosY);
bucky.draw(shiftX, shiftY);
g.drawString("Bucky Xpos = "+buckyPosX+"\nBucky YPos = "+buckyPosY,400,20);
if(quit)
{
g.drawString("Resume(R)\nMenu(M)\nExit(Q)", 150, 200);
if(!quit) g.clear();
}
}
public void update(GameContainer gc, StateBasedGame sbg, int delta)
throws SlickException {
// TODO Auto-generated method stub
Input input = gc.getInput();
if(!quit)
{
if(input.isKeyDown(Input.KEY_UP))
{ bucky = movingUp;
buckyPosY += delta * 0.1f;
if(buckyPosY > 162)
buckyPosY -= delta * 0.1f;
}
if(input.isKeyDown(Input.KEY_DOWN))
{ bucky = movingDown;
buckyPosY -= delta * 0.1f;
if(buckyPosY <- 600)
buckyPosY += delta * 0.1f;
}
if(input.isKeyDown(Input.KEY_LEFT))
{ bucky = movingLeft;
buckyPosX += delta * 0.1f;
if(buckyPosX > 324)
buckyPosX -= delta * 0.1f;
}
if(input.isKeyDown(Input.KEY_RIGHT))
{ bucky = movingRight;
buckyPosX -= delta * 0.1f;
if(buckyPosX < -840)
buckyPosX += delta * 0.1f;
}}
if(input.isKeyDown(Input.KEY_ESCAPE))
quit = true;
if(quit)
{
if(input.isKeyDown(Input.KEY_R))
quit = false;
if(input.isKeyDown(Input.KEY_M))
sbg.enterState(1);
if(input.isKeyDown(Input.KEY_M))
System.exit(0);
}
}
}
Thank You Very Much !!
You're switching to your play state in your play state. In the Play class, put, sbg.enterState(0) instead of sbg.enterState(1).

Categories