sacOO7 / socketcluster-client-java

Native java and android client for socketcluster framework in node.js
http://socketcluster.io/
Apache License 2.0
94 stars 42 forks source link

Emitter.Listener callback not compiles. Not works. #28

Closed Hayk985 closed 6 years ago

Hayk985 commented 6 years ago

Hi, I'm creating socket client part, and I have a problem in Emitter.Listener. The listener not throws any exception, it only not compiles. SO when I'm doing debug, and I set breakpoint in that callback, it jumps over the call. I have some pictures where I explain my problem very well. screen shot 2018-04-13 at 4 17 52 pm screen shot 2018-04-13 at 4 24 22 pm screen shot 2018-04-13 at 4 24 53 pm screen shot 2018-04-13 at 4 53 07 pm screen shot 2018-04-13 at 4 53 22 pm Any ideas why it's not working. It connects well, and the state is OPEN, but in that call I have to send my tokens into server.

Hayk985 commented 6 years ago

From server they said that they have an exception like this SocketProtocolError: Client pong timed out. I have no problem with access and refresh tokens. And the internet connection is great, if I have an internet connection problem, I can't to connect. But I'm connecting successful.

Yes and one more thing too. I moved the socket.connect() method after the listener and socket.on(), and now in debug mode it not gives exception like "socket = no such instance field: 'val$socket' ".

sacOO7 commented 6 years ago

Sure, I will take a look at it @hyko

On Apr 13, 2018 9:19 PM, "Hayko985" notifications@github.com wrote:

From server they said that they have an exception like this SocketProtocolError: Client pong timed out. I have no problem with access and refresh tokens. And the internet connection is great, if I have an internet connection problem, I can't to connect. But I'm connecting successful.

Yes and one more thing too. I moved the socket.connect() method after the listener and socket.on(), and now in debug mode it not gives exception like "socket = no such instance field: 'val$socket' ".

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sacOO7/socketcluster-client-java/issues/28#issuecomment-381178355, or mute the thread https://github.com/notifications/unsubscribe-auth/AP8vSSpn8BJ4Iv0Qj6bkhJ6XOk1yZezCks5toMjvgaJpZM4TTcDe .

Hayk985 commented 6 years ago

Thank you very much, please help me if you can)) @sacOO7

Hayk985 commented 6 years ago

If you want I can give you my vk)))

Hayk985 commented 6 years ago

@sacOO7 Hi)) How are you? Please can you help me to fix this problem, tomorrow is the last day, and if i can't do this, they will not bring me to work. So please, help me if you can)) Thank you.

Hayk985 commented 6 years ago

@sacOO7 Here is my vk, you can connect with me)) https://vk.com/id192526595

sacOO7 commented 6 years ago

Hi @hyko, sorry for late reply. Little busy those days. Will get back to you for sure (today night ...., Probably after 2-3 hours)

On Apr 15, 2018 4:44 PM, "Hayko985" notifications@github.com wrote:

@sacOO7 https://github.com/sacOO7 Here is my vk, you can connect with me)) https://vk.com/id192526595

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sacOO7/socketcluster-client-java/issues/28#issuecomment-381398311, or mute the thread https://github.com/notifications/unsubscribe-auth/AP8vSc8w5GecHxhtp2mnkwxPVW4t_1cbks5toyuPgaJpZM4TTcDe .

Hayk985 commented 6 years ago

@sacOO7 hey bro) I think you can't help me today. If you can't, then can you help me tomorrow, but soon? And how can I connect with you? Any vk, whatsapp or something else.

sacOO7 commented 6 years ago

Hi @Hayko985, Can you explain for which event are you exactly trying to listening to?

sacOO7 commented 6 years ago

Sending auth data is not supposed to be inside listener

sacOO7 commented 6 years ago

Instead before connecting call socket.setAuthToken("Your JWT token here")

sacOO7 commented 6 years ago

You can see that method here https://github.com/sacOO7/socketcluster-client-java/blob/master/src/main/java/io/github/sac/Socket.java#L90

sacOO7 commented 6 years ago

Please post here context of your problem as well as little server code that sends data so that I can understand exact problem. You can email me your context for the code if you do not want to post it here...

Hayk985 commented 6 years ago

Ok, so when I'm giving my jsonobject to that data, instead I need to use setAuthToken. I'm listening to connect event. I'm beginner yet in sockets)) Server says that client not sends pong. What is this pong and how to send it?

Hayk985 commented 6 years ago

Yeah and I have no the server code. I'm doing only the client part)

Hayk985 commented 6 years ago

@sacOO7 Hi) How are you? I done socket.setAuthToken("Your JWT token here"), but that not helped. Server says that client not sends pong. So you know what is that pong and how to send it?

sacOO7 commented 6 years ago

Hi @Hayko, if you are not writing any server code, you don't need to set auth token. You can check example working code here https://github.com/sacOO7/socketcluster-client-java/blob/master/src/main/java/Main.java

On Apr 16, 2018 1:02 PM, "Hayko985" notifications@github.com wrote:

@sacOO7 https://github.com/sacOO7 Hi) How are you? I done socket.setAuthToken("Your JWT token here"), but that not helped. Server says that client not sends pong. So you know what is that pong and how to send it?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sacOO7/socketcluster-client-java/issues/28#issuecomment-381506012, or mute the thread https://github.com/notifications/unsubscribe-auth/AP8vSXSkZbK7VB5mGOkFUuBDvHGIn4g9ks5tpEkIgaJpZM4TTcDe .

sacOO7 commented 6 years ago

Generally auth token is set by server itself, you will receive it and save it.Then reuse it using set auth token method. You will receive token in onsetAuthtoken callback, there you can save it and use it again.

On Apr 16, 2018 1:10 PM, "Sachin Shinde" sachinshinde7676@gmail.com wrote:

Hi @Hayko, if you are not writing any server code, you don't need to set auth token. You can check example working code here https://github.com/ sacOO7/socketcluster-client-java/blob/master/src/main/java/Main.java

On Apr 16, 2018 1:02 PM, "Hayko985" notifications@github.com wrote:

@sacOO7 https://github.com/sacOO7 Hi) How are you? I done socket.setAuthToken("Your JWT token here"), but that not helped. Server says that client not sends pong. So you know what is that pong and how to send it?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sacOO7/socketcluster-client-java/issues/28#issuecomment-381506012, or mute the thread https://github.com/notifications/unsubscribe-auth/AP8vSXSkZbK7VB5mGOkFUuBDvHGIn4g9ks5tpEkIgaJpZM4TTcDe .

Hayk985 commented 6 years ago

@sacOO7 I done as in this example and in logs it says "Authentication is required (optional)". So in socket.setlistener(new BasicListener{}) there is a method onSetAuthToken(). I need to give here my jwt?

Hayk985 commented 6 years ago

screen shot 2018-04-16 at 12 41 40 pm

Hayk985 commented 6 years ago

@sacOO7 I'm beginner in this sockets and sorry for disturbing you, but i need your help))

sacOO7 commented 6 years ago

Hi @Hayko985, I am not sure why you are sending auth event to server

sacOO7 commented 6 years ago

Can you put your server URL here? Also before sending data make sure you get connected to the server in response.

Hayk985 commented 6 years ago

@sacOO7 Hi)) After long suffering I'm already sending my pong)) So in server there is no any pong exception. The only issue is now that I'm using oauth2 and I can't to send jwm, I need to send my oauth object, so my access token and refresh token.

Let me show some of the server logs and you'll see the exceptions.

[Warning] AuthTokenInvalidError: jwt malformed at emitOne (events.js:96:13) at Socket.emit (events.js:189:7) at readableAddChunk (_stream_readable.js:176:18) at Socket.Readable.push (_stream_readable.js:134:10) at TCP.onread (net.js:551:20) name: 'error', length: 202, severity: 'ERROR', code: '42883', detail: undefined, hint: 'No operator matches the given name and argument type(s). You might need to add explicit type casts.', position: '497', internalPosition: undefined, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'parse_oper.c', line: '728', routine: 'op_error' } newuser info socket is KCtCwozsPkSRE0AE (node:12084) UnhandledPromiseRejectionWarning: Unhandled promise rejection (reje ction id: 6): TypeError: Cannot read property '0' of undefined

So any idea bro? Yeah and thank you very much for that help.

sacOO7 commented 6 years ago

Can you give me the context of your server code? I am not sure how it is working or supposed to work. Normally if you start socketcluster server, on normal mode, you do not require to send JWT.

On Apr 16, 2018 6:31 PM, "Hayko985" notifications@github.com wrote:

@sacOO7 https://github.com/sacOO7 Hi)) After long suffering I'm already sending my pong)) So in server there is no any pong exception. The only issue is now that I'm using oauth2 and I can't to send jwm, I need to send my oauth object, so my access token and refresh token.

Let me show some of the server logs and you'll see the exceptions.

[Warning] AuthTokenInvalidError: jwt malformed at emitOne (events.js:96:13) at Socket.emit (events.js:189:7) at readableAddChunk (_stream_readable.js:176:18) at Socket.Readable.push (_stream_readable.js:134:10) at TCP.onread (net.js:551:20) name: 'error', length: 202, severity: 'ERROR', code: '42883', detail: undefined, hint: 'No operator matches the given name and argument type(s). You might need to add explicit type casts.', position: '497', internalPosition: undefined, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'parse_oper.c', line: '728', routine: 'op_error' } newuser info socket is KCtCwozsPkSRE0AE (node:12084) UnhandledPromiseRejectionWarning: Unhandled promise rejection (reje ction id: 6): TypeError: Cannot read property '0' of undefined

So any idea bro? Yeah and thank you very much for that help.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sacOO7/socketcluster-client-java/issues/28#issuecomment-381591040, or mute the thread https://github.com/notifications/unsubscribe-auth/AP8vSeVd2y1F3QF27xmEZ05F9lr54H-Sks5tpJYjgaJpZM4TTcDe .

Hayk985 commented 6 years ago

I have only the source code of page, so I can send you only the scrypt part.

Hayk985 commented 6 years ago

https://drive.google.com/file/d/17exVT9XVIbZkuZWFwz1ew-Zg8l8-FHgu/view . Here the scrypt part. It need oauth, because in my application I'm doing user authentication with Oauth2. So I'm not using jwt in my app.

sacOO7 commented 6 years ago

I see

On Apr 16, 2018 6:57 PM, "Hayko985" notifications@github.com wrote:

https://drive.google.com/file/d/17exVT9XVIbZkuZWFwz1ew-Zg8l8-FHgu/view . Here the scrypt part. It need oauth, because in my application I'm doing user authentication with Oauth2. So I'm not using jwt in my app.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sacOO7/socketcluster-client-java/issues/28#issuecomment-381598559, or mute the thread https://github.com/notifications/unsubscribe-auth/AP8vSf96L4A2DMmz5HiNIOu5-YvMb1Brks5tpJxBgaJpZM4TTcDe .

sacOO7 commented 6 years ago

Is this server code written by you? or is it a chatroom service... I just want to know if that code is working. If it is working code, then I might be able to give you the solution. I am assuming you already have accessToken and refreshToken available.

Hayk985 commented 6 years ago

This is for chatroom)) Yes I have accessToken and refreshToken. But wait a while because they are doing work on server and now it's unavailable))

sacOO7 commented 6 years ago

Just a quick question... Are you able to connect to server. I believe you should receive connected to server in onconnect function callback. More precisely, Connected to endpoint. Forget code after sc.connectAsync() function.

sacOO7 commented 6 years ago

Just write down this code after sc.connectAsync method call.

JSONObject authObject = new JSONObject();
authObject.put("accessToken", "Your access token here");
authObject.put("refreshToken", "Your refresh token here");
sc.emit("auth", authObject);
Hayk985 commented 6 years ago

Yes of course. Yeah and I changed the connectAsync() to connect() and moved it into thread. So I don't know what's the difference between this two, because it's connects anyway.

Hayk985 commented 6 years ago

screen shot 2018-04-16 at 6 23 27 pm Here my new code))

Hayk985 commented 6 years ago

Here my code after adding the JsonObject part

screen shot 2018-04-16 at 6 26 37 pm

sacOO7 commented 6 years ago

What is sc.on("connect"). You do not need it.

Hayk985 commented 6 years ago

@sacOO7 I saw it in server code, I thought I need it. Ok but what is that method means?

sacOO7 commented 6 years ago

To get whether you get connected or not, you need to register basic listener. I think, you probably need to take a look at documentation on repo( https://github.com/sacOO7/socketcluster-client-java). It will solve most of your problems :+1:

Hayk985 commented 6 years ago

Yeah I done already the basic listener, that not visible in picture))) screen shot 2018-04-16 at 7 11 07 pm

Hayk985 commented 6 years ago

Oh I understood. So with socket.on() I can get message from server and with socket.emit() I can send data to server. I'll read the documentation today)) The server not works yet)))

Hayk985 commented 6 years ago

@sacOO7 Ok man, tomorrow I'll try to connect to server, if there will be any excepions, I'll say you. Thank you very much.

Hayk985 commented 6 years ago

@sacOO7 Hi) How are you? So I done something like this as you said, but the server not gets my data, that I'm sending with emit. Watch here. screen shot 2018-04-17 at 1 00 00 pm

Hayk985 commented 6 years ago

@sacOO7 Man there's another little problem, I don't know why is it working like this, but when I'm running my app, that not sends data to server, but when I'm doing debug, it sends the data successful, but when it sends there's an error too.

Here the error log. error TypeError: Cannot read property 'username' of undefined at process._tickCallback (internal/process/next_tick.js:103:7) newuser info socket is 08GaAmezm27PcvAD (node:1416) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejec tion id: 3): TypeError: Cannot read property '0' of undefined

Hayk985 commented 6 years ago

@sacOO7 I fixed the username part. When I'm doing debug all works good without any errors in server. But when I'm doing run it says [Warning] InvalidActionError: Cannot subscribe socket to a channel before it has completed the handshake

sacOO7 commented 6 years ago

Yeah I know the problem. Wait for 15-20 mins. Will get back to you on this ...

On Apr 17, 2018 5:53 PM, "Hayko985" notifications@github.com wrote:

@sacOO7 https://github.com/sacOO7 I fixed the username part. When I'm doing debug all works good without any errors in server. But when I'm doing run it says [Warning] InvalidActionError: Cannot subscribe socket to a channel before it has completed the handshake

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sacOO7/socketcluster-client-java/issues/28#issuecomment-381973078, or mute the thread https://github.com/notifications/unsubscribe-auth/AP8vSW6v_gjGQGkYr6pbK_tPUDwHgLUSks5tpd7UgaJpZM4TTcDe .

Hayk985 commented 6 years ago

@sacOO7 Ok I'll wait you bro) Thanks a lot)))

sacOO7 commented 6 years ago

Hi @Hayko985 , the problem is because, you are trying to subscribe before handshake is made with server. I think you should emit auth event inside onConnected callback. It should work.

Hayk985 commented 6 years ago

@sacOO7 Hi)) All works thanks. So one more question too. Is there any watch method in client part? screen shot 2018-04-17 at 6 12 09 pm

That's in server part. How can I do this in client part?

Hayk985 commented 6 years ago

I fixed this using channel.onMessage() method... Thank you very very much. If there will be more questions too, I'll ask you.

sacOO7 commented 6 years ago

Since problem is solved, I will close the issue ..