Server to Client return call problem.

61 views
Skip to first unread message

Jonathan

unread,
Aug 15, 2012, 4:08:12 AM8/15/12
to smartsock...@googlegroups.com
(Disclaimer: I am new to programming)

I've had your site bookmarked for a month now and have finally had a chance to go through your tutorials (the new ones).  It took me a quick google search to fix the first problem I ran into (deprecated json function call using encode instead of stringify in SmartSocketClient.as), and everything seems to run fine after that ( other than the warning about var 'i' having no type declaration in RemoteCall.as).

However while the fully created tutorial runs without errors, the return call from server to client isn't happening for me.  I'm talking about this code here:

public void greeting(TCPClient client, JsonObject json) {
        Logger.log( "Client said: "+json.get( "message" ).getAsString() );
       
        RemoteCall call = new RemoteCall("onGreeting", json.get("directTo").getAsString());
        call.put("serverResponse", "Hi, I recieved your greeting!");
        client.send(call);

    }

I would expect to see this return call in my server log, but all I get is ...

[Config]    Configuration loading is complete.
[TCPExtension]    [SmartSocketTut1] Extension running on port 8888
[SmartSocketTut1]    I'm ready
[TCPExtension]    [SmartSocketTut1] New client accepted:
[TCPClient]    Client connected from: 127.0.0.1
[TCPClient]    There are currently: 3 thread active in this group.
[TCPClient]    Sending crossdomain policy file.
[TCPClient]    Client 10 says: {"directTo":"main","method":"greeting","message":"Client greeting!"}
[SmartSocketTut1]    Client said: Client greeting!

As you can see the server doesn't seem to be processing the return call at all.

What am I missing?

jonatha...@gmail.com

unread,
Aug 15, 2012, 4:23:46 AM8/15/12
to smartsock...@googlegroups.com, jonatha...@gmail.com
I should add that my client opens in a browser, while yours seems to open in flash builder somewhere...

I'm using Flash Builder 4.6, and NetBeans 7.

Xaero Degreaz

unread,
Aug 15, 2012, 10:09:45 AM8/15/12
to smartsock...@googlegroups.com, jonatha...@gmail.com
Hi, thanks for the report.

Are you using the packages from the download section, or the source code in the trunk?

Also, ensure that you are not using the BINARY RemoteCalls to pass information to the Flash client (I have not updated the Flash client API to use this new functionality) -- There are two different types of RemoteCalls (check your import settings at the top of your code :) )

Let me know if there

Xaero Degreaz

unread,
Aug 15, 2012, 10:20:53 AM8/15/12
to smartsock...@googlegroups.com, jonatha...@gmail.com
Sorry, let me know if there are any other problems, or questions.

I'm at work and wasn't paying attention to the missing part of the email =)

Jonathan

unread,
Aug 15, 2012, 10:24:17 AM8/15/12
to smartsock...@googlegroups.com
Hey thanks for the reply,

1. I am using the sources available through the Download link on smartsocket.net, as it shows in the video.

2. Re: BINARY RemoteCalls... I only see one import option when I add this line:


RemoteCall call = new RemoteCall("onGreeting", json.get("directTo").getAsString());

... that import option is:

import net.smartsocket.protocols.json.RemoteCall;

.... Server-Side code:

package smartsockettut1;

import com.google.gson.JsonObject;
import net.smartsocket.Config;
import net.smartsocket.Logger;
import net.smartsocket.protocols.json.RemoteCall;
import net.smartsocket.serverclients.TCPClient;
import net.smartsocket.serverextensions.TCPExtension;

public class SmartSocketTut1 extends TCPExtension {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Config.useGUI = false;
        new SmartSocketTut1().start();
    }
   
    public SmartSocketTut1 () {
        super(8888);

    }
   
    public void greeting(TCPClient client, JsonObject json) {
        Logger.log( "Client said: "+json.get( "message" ).getAsString() );
       
        RemoteCall call = new RemoteCall("onGreeting", json.get("directTo").getAsString());
        call.put("serverResponse","Hi, I recieved your greeting!");
        client.send(call);
    }

    @Override
    public void onExtensionReady() {
        Logger.setLogLevel(0);
        Logger.log("I'm ready");
    }

    @Override
    public void onConnect(TCPClient client) {
       
    }

    @Override
    public void onDisconnect(TCPClient client) {
      
    }

    @Override
    public boolean onDataSpecial(TCPClient client, String methodName, JsonObject params) {
       return false;
    }
}

.....  Client-Side code:


 package {
    import flash.display.Sprite;
    import flash.events.*;
   
    import net.smartsocket.SmartSocketClient;
    import net.smartsocket.protocols.json.RemoteCall;
   
    public class sstut1 extends Sprite {
       
        public var s:SmartSocketClient = new SmartSocketClient();
       
        public function sstut1() {
            SmartSocketClient.addDataListener("main", this);
            s.addEventListener(Event.CONNECT, onConnect);
            s.connect("localhost", 8888);
        }
       
        public function onConnect(event:Event):void {
            var call:RemoteCall = new RemoteCall( "greeting", "main" );
            call.message = "Client greeting!";
            SmartSocketClient.send(call);
        }
       
        public function onGreeting(call:RemoteCall):void {
            trace(call.serverResponse);
           
        }
    }
}

Xaero Degreaz

unread,
Aug 15, 2012, 10:31:03 AM8/15/12
to smartsock...@googlegroups.com, jonatha...@gmail.com
At first glance, your code looks just fine. Be sure you check in the console of Flash development environment (that's where you should be seeing your expected debug responses)


On Wednesday, August 15, 2012 3:08:12 AM UTC-5, Jonathan wrote:

Xaero Degreaz

unread,
Aug 15, 2012, 10:58:48 AM8/15/12
to smartsock...@googlegroups.com, jonatha...@gmail.com
You also mentioned that you are running your client in the browser, so you'll not be seeing your debug logs. Try doing a test movie (ctrl + enter if I remember right) from within Flash, this way you have access to the console, and can verify things are working.

Jonathan

unread,
Aug 15, 2012, 11:52:57 AM8/15/12
to smartsock...@googlegroups.com
The mention of "debug logs" did the trick for me.  I couldn't find any mention of running the client as a "test movie" in Flash Builder 4.6, but after uninstalling flash player and installing the debugger flash player I was able to run the client in debug mode which gave me the console.  Thanks very much for pointing me in the right direction.

Is there a way to log server->client calls on the server side as well?

Another, perhaps poorly formed, question.  I have been reading a lot about other communication options like LCDS, WebORB, BlazeDS, webSockets, XMLSocket, etc.  Do you think your communication layer is capable of thousands of concurrent connections in the same way these other frameworks are?  I am barely scratching the surface here, but from what I have read persistent socket connections are the way to go for ease of use ( websockets/html5, xmlsocket ).

If my intentions were to develop a communication layer for a single server and a few thousand concurrently connected clients what sort of problems do you think I would see using SmartSocket?

Also, perhaps you can point me in the right direction for assigning a server-side variable to a client object that persists in memory as long as the client remains connected.  Ideally I would assign a key/value to each client that successfully passed through my login function and all remote server-side functions would require this key/value.  Would that be an effective way of securing my app?

Sorry for all the questions... heh.  Please don't feel obligated to answer, I know I still have plenty of work to do on my own.

Thanks again for the replies.

Xaero Degreaz

unread,
Aug 15, 2012, 12:04:30 PM8/15/12
to smartsock...@googlegroups.com, jonatha...@gmail.com
SmartSocket would scale quite well! Every client has its own communication thread, so as long as your machine itself can keep up with memory usage, you should be fine. Also, you can set the console (Config.useConsole [I think that's it, I can't remember at this moment]) to false and that will make the server run in a basic command prompt, and conserve actual ram for the user interface.

You can control your own logging in your extension, or you can download the source code for the server, and modify the back-end to show any type of logging you want. You'll just need to compile it from source. Also, you'll want to take care of logging too much information with the default user interface -- the log is never cleared, so that stuff can clog up memory, so make sure when you're not in active development, to set the log level to something higher, and explicitly define your log events at, or above your log level :)

If you're wanting to have some persistent connection information with your logged in users, you can create your own "player" objects, and in each object, you can store their TCPClient in a variable, and have other useful stuff, such as scores, etc.

If you're looking for something that's pre-setup for you, you should check out using SmartLobby. Basically, it's an extension that I created for you (using the same types of methods that you see in your tutorial, it's just quite a bit more complete). It handles rooms, players, games, chatting, etc. There's currently no tutorial recorded for it, but there's some pretty good example stuff in the downloaded packages you've downloaded :) Complete with code.

It's not a bother to answer questions, and sorry if this email seems kinda rushed around, and off in different directions; I'm currently at work and handling customers at the same time ;)

Jonathan

unread,
Aug 15, 2012, 12:12:54 PM8/15/12
to smartsock...@googlegroups.com
I think I understood enough of what you just said to keep me busy for a while.

Thanks again.

Jonathan

unread,
Aug 18, 2012, 7:09:20 AM8/18/12
to smartsock...@googlegroups.com
Having reliability issues (I'm assuming due to the nature of TCP).  The first time I run the client the remote calls display properly, but if I run the client multiple times (whether first closing the previous instance or not) the return remote call to onGreeting often gets lost.  Basically the console acts as though there was no return call from the server at all.

I've tried to work it out using flushes and setting socket.setTcpNoDelay(true), but nothing has alleviated the problem yet.

Is this merely a logging/display problem related to running both the server/client on the same pc?  Everything I've read tells me that TCP sends the data when it's ready (meaning sometimes slowly), but I'm not seeing a delay here.  Instead I'm seeing a complete failure on the clients part in recognizing a remote call from the server.  Sometimes it works fine 5+ times in a row, other times it fails 5+ times in a row.

Any ideas?

Xaero Degreaz

unread,
Aug 18, 2012, 2:32:28 PM8/18/12
to smartsock...@googlegroups.com, jonatha...@gmail.com
Sorry to hear you're having problems.

Are you running inside the Netbeans environment? If so, check in the console, it will display all incoming and outgoing traffic. See if the packet is being sent, or if there are any errors. I'm not sure where you're having any problems. Tons of testing was done while running on the same machine. I did notice problems with sending packets back to back (sometimes two packets would get squashed together), but I've accounted for that by adding line terminators to each packet, and then processing each line individually on Flash side.

There has been a lot of good work done on SmartSocket since I uploaded the packages that you've downloaded. I do have a 2.1.0 of the actual server that's ready, but I haven't really released it, because there is hasn't been an ActionScript 3.0 API update for a lot of the new features (and I didn't want people to get confused as to why stuff didn't work).

Anyhow, I'll give you the links, and you let me know how this works out for you. Just remember, in this version there are two RemoteCall methods from the server side. Flash will only be able to use the JSON [deprecated in this version] one, not the BINARY for the moment.

Server:

JavaDoc:

Sources:

Or, if you prefer to build it out from source, feel free to either download the source, or checkout the repository with Git.

Let me know if you need anything else.

Jonathan

unread,
Aug 18, 2012, 9:09:54 PM8/18/12
to smartsock...@googlegroups.com
I am still running the client/server just as it shows in your tutorial; the server is running in netbeans while the client is started from flash builder in debug mode, opening in a browser, with the console showing in flash builder.

I have been trying to figure out how to accomplish this:


"Are you running inside the Netbeans environment? If so, check in the console, it will display all incoming and outgoing traffic. See if the packet is being sent, or if there are any errors."

... but I have not had any success figuring out how to show the socket traffic in netbeans.  All I get is the messages sent using Logger.log.

I have run the server in debug mode, tried to attach various debuggers, and tried using profile as well.  After several hours of google searching and various attempts I haven't seen anything that shows me the socket traffic in netbeans.

Could you point me in the right direction?  Or if I need to download/install some 3rd party module that allows me to view the traffic maybe you could recommend one.  That type of software is usually plagued with the kind of junk that leads me to another reformat session.

I'm going to end up just throwing together a simple UI on the client using a series of buttons to check the connection that way.  But this isn't really going to cut it long-term.  It would be much better to have a reliable way to monitor the traffic between server/client.  The current method (using the flash debug player and debugging console in Flash Builder) is extremely unreliable (unless it's accurate and secondary remote calls fail more often than they succeed).

Still a bit lost here, but not giving up.

Xaero Degreaz

unread,
Aug 21, 2012, 1:17:04 PM8/21/12
to smartsock...@googlegroups.com, jonatha...@gmail.com
Sorry for the late reply!!

Ok, I think you may have somewhat of a setup problem. I use Flash Builder simply to script in, but the actual launching of the Flash client happens inside Flash itself. Do you have Flash? You don't need any debugger version -- I see you said that you got the debugger version, it's not needed. You *need*:

1. Your choice of ActionScript 3.0 authoring tool (I happen to use Flash Builder, but there are other free ones that work)
2. Flash (I can't remember when AS3, came out, but I'm thinking you need at LEAST Flash MX, mayyybe 2008 or above [CS5 is the latest]) [Note, this is not the web player, this is the actual development environment {free trials are available from adobe}]
3. Your choice of Java development environment (I prefer Netbeans, and it's what I did the tutorials in, but anything should work)

Inside Netbeans, at the bottom, there should be a console. This is where messages are printed that are not actually displayed in the SmartSocket console -- two completely separate entities (System.out calls are posted in the Netbeans console, much like you would see in a command prompt). I wasn't talking about a bandwidth monitor. In the actual System.out calls I trace everything incoming and outgoing. It basically happens behind the scenes, and you won't see it in the main SmartSocket console.

If you nee further assistance, please, contact me on my Google Talk, and I'd be happy to give you a live tutorial. XaeroD...@gmail.com

Thanks for not giving up.

-Jerome

jonatha...@gmail.com

unread,
Aug 21, 2012, 8:08:55 PM8/21/12
to smartsock...@googlegroups.com
I may need a video, as much as I hate to admit it (without so much camera zooming perhaps).

I can find no System.out calls in TCPClient or TCPExtension.  Unless I run the server with useGUI = false I don't have any messages in the netbeans console.

I have flash (Flash Pro 5.5), but I'm not sure where you would launch from.  In order to get the output you show in your video I had to get the debugger version of flash player and then launch the client from flash builder in debug mode.  Are you saying you don't launch the client from flash builder at all? 

I tried to export a release build of the client from Flash Builder and open it with Flash Pro but I ended up with the error:

"ReferenceError: Error #1065: Variable JSON is not defined."

The flash side of things is very new to me, so any help would be welcome.

Jonathan

unread,
Aug 22, 2012, 2:45:55 AM8/22/12
to smartsock...@googlegroups.com
Ok, all sorted.  I was creating the project in Flash Builder, not Flash Professional, and being new to flash I didn't catch on to the interplay between the two in your video.

It's all working properly now, and I'm seeing the proper console messages each time.

Now to just figure out why the client hits the server twice if I open the html or swf release build files. Bolded the part that shouldn't be there.

TCPClient:    Client 43 says: �
TCPClient:    [SmartSocketTut1] Client has tried to pass invalid JSON
TCPClient:    Client 43 disconnected.
TCPExtension:    [SmartSocketTut1] New client accepted:
TCPClient:    Client connected from: 127.0.0.1
TCPClient:    There are currently: 7 thread active in this group.
TCPClient:    Sending crossdomain policy file.
TCPClient:    Client 44 says: {"message":"Client greeting!","method":"greeting","directTo":"main"}
TCPClient:    Client 44 disconnected.

When I launch the client using cntrl-enter in Flash Builder I don't get the bold part above.  Then again I am probably just misunderstanding the proper way to launch the client outside of any IDE.

Really sorry about all this Jerome.  I had no clue about Flash Professional at all before I started all this, and only heard you mention Flash Builder in the tutorial.

Xaero Degreaz

unread,
Aug 22, 2012, 8:18:14 AM8/22/12
to smartsock...@googlegroups.com, jonatha...@gmail.com
Glad you got all that sorted out :)

There are a couple options for why that message is being logged:

#1 Usually when I see this, it happens when trying to connect to your server through the browser by typing in http://youripaddress:smartSocketPort. This has the browser try to connect to your server, and it sends HTTP headers to the server, which of course are not JSON.

#2 When running the client from the browser, Flash sends a crossdomain policy request, which is XML, not JSON. The server should then send the crossdomain policy file in your configuration file. In any event, I would disregard that log, since SmartSocket will just discard the incoming packet as garbage :)

Yeah Cntrl+Enter is how I was launching it in the tutorials. Flash Builder just sends a "build" request to the Flash development environment, and it launches from there. When launching inside your Flash environment, no crossdomain pollicy request is needed, which is why you don't see that first error.

Also, when you typed this:
TCPClient:    Client 43 says: �

The part after "Client 43 says" is some unrecognized character that I can't seem to see. What does it look like? Screenshot?

No problem, and no need to be sorry about anything. Just glad you're using the program, and didn't give up -- SmartSocket is just too easy to use for pretty much any type of server - client related project.

As always, Jonathan, if you need anything else, let me know.

Jonathan

unread,
Aug 22, 2012, 11:12:10 PM8/22/12
to smartsock...@googlegroups.com
The symbol shows up as an empty square so it is probably not fully displaying in the console either.

Xaero Degreaz

unread,
Aug 22, 2012, 11:39:52 PM8/22/12
to smartsock...@googlegroups.com

Hmm... now I'm interested in knowing what exactly that is being sent. The only thing I can think of is a policy request, but it should be plain text.

I'll look into it. Anyhow, the server is doing nothing with it.

Xaero Degreaz

unread,
Sep 20, 2012, 12:38:30 AM9/20/12
to smartsock...@googlegroups.com
How are things coming along?

jonatha...@gmail.com

unread,
Sep 20, 2012, 2:23:58 AM9/20/12
to smartsock...@googlegroups.com
Working through building the UI in as3.  It's going to be a while before I get back to server/client communication.

Xaero Degreaz

unread,
Sep 20, 2012, 2:25:47 AM9/20/12
to smartsock...@googlegroups.com
Anything specific you care to share? SmartLobby has several built- in components that may aid you :))

Jonathan

unread,
Sep 20, 2012, 2:52:59 AM9/20/12
to smartsock...@googlegroups.com
I haven't modified it at all yet, but my current plan is to limit the clients initially to a login method, after which their server-assigned client name would be modified to an array containing a few simple integers that allow me to effectively route necessary data pushes.  Basically unless the clients have gone through the login method successfully they would be unable to call any other method.  And once they successfully log in, the server-side modified client name will be a necessary part of each method call.

I don't currently have any client side code connecting to the server, so I am still far from testing and adaptation.

Xaero Degreaz

unread,
Sep 20, 2012, 3:02:04 AM9/20/12
to smartsock...@googlegroups.com
Alright, well as always man: let me know if you need any help whatsoever. I'm always around, and willing to help out (of course at no charge) with any implementation you may have in regards to SmartSocket.
Reply all
Reply to author
Forward
0 new messages