Simple Java Client Examples?

Post here your questions about the Java client / Android API for SFS2X

Moderators: Lapo, Bax

homerlex
Posts: 48
Joined: 16 Aug 2012, 15:13

Re: Simple Java Client Examples?

Postby homerlex » 20 Aug 2012, 13:13

Yes, as I mentioned, I updated the server AND the client. sfsClient,getVersion() shows 1.0.1.

Below is the latest code (with the client version println) and the latest output:

Code: Select all

package smartclient;

import com.smartfoxserver.v2.exceptions.SFSException;
import sfs2x.client.SmartFox;
import sfs2x.client.core.BaseEvent;
import sfs2x.client.core.IEventListener;
import sfs2x.client.core.SFSEvent;

public class TestClient implements IEventListener {

    SmartFox sfsClient;

    @Override
    public void dispatch(final BaseEvent event) throws SFSException {

        if (event.getType().equalsIgnoreCase(SFSEvent.CONNECTION)) {
            if (event.getArguments().get("success").equals(true)) {
                System.out.println("Connection Successful");
                onDestroy();
            } //otherwise error message is shown
            else {
                System.out.println("ERROR: Connection Not Successful");
            }
        }
    }

    public void start() {
        sfsClient = new SmartFox();
        String version = sfsClient.getVersion();
        System.out.println("Client Version: " + version);
       
       
        sfsClient.addEventListener(SFSEvent.CONNECTION, this);
        sfsClient.connect("localhost", 9933);
    }

    protected void onDestroy() {
        if (sfsClient != null) {           
            sfsClient.removeAllEventListeners();
            System.out.println("About to disconnect ...");
            sfsClient.disconnect();
            System.out.println("Yay, disconnected");
            sfsClient = null;
        }
    }

    public static void main(String[] args) {
        TestClient client = new TestClient();
        client.start();
    }
}


Code: Select all

Client Version: 1.0.1
127 [New I/O client worker #1-1] INFO sfs2x.client.core.EventDispatcher - Dispatching event OnConnect to 1 listeners
127 [New I/O client worker #1-1] INFO sfs2x.client.core.EventDispatcher - Dispatching event connect to 1 listeners
146 [New I/O client worker #1-1] INFO sfs2x.client.core.EventDispatcher - Dispatching event OnData to 1 listeners
Connection Successful
About to disconnect ...
146 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - Handling New Packet of size 80
146 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - Handling Header Size. Length: 79 (small)
146 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - Data size is 77
146 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - Handling Data: 77, previous state: 0/77
146 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - <<< Packet Complete >>>
149 [New I/O client worker #1-1] INFO sfs2x.client.core.EventDispatcher - Dispatching event connection to 1 listeners
149 [New I/O client worker #1-1] INFO sfs2x.client.core.EventDispatcher - Dispatching event OnDisconnect to 1 listeners
149 [New I/O client worker #1-1] INFO sfs2x.client.core.EventDispatcher - Dispatching event disconnect to 1 listeners
homerlex
Posts: 48
Joined: 16 Aug 2012, 15:13

Re: Simple Java Client Examples?

Postby homerlex » 22 Aug 2012, 12:33

Any thought on why I'm still seeing this behavior?

Return to “SFS2X Java / Android API”

Who is online

Users browsing this forum: No registered users and 1 guest