#1 2017-01-25 14:07:25

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

Question about WebSockets clients and servers

Hello,
I am trying to understand why my WebSockets never receive the "Open" event. Using several other language, I can connect to my server just opening a socket.

What I receive on the server's part is way more information than just the connection. Perhaps could I send an information to AppBuilder to let it know it is connected ?

Below are the lines I get on the server. [IP] is my remote local IP

Server started
Connection [IP]:720
[IP]:720: GET / HTTP/1.1
[IP]:720: Origin: http://127.0.0.1:9999
[IP]:720: Sec-WebSocket-Key: KotwQBSJ00N90ijzO6dHEw==
[IP]:720: Connection: Upgrade
[IP]:720: Upgrade: websocket
[IP]:720: Sec-WebSocket-Version: 13
[IP]:720: Host: [HOST_IP:HOST_PORT]
[IP]:720: Cache-Control: no-cache
[IP]:720: 

Many thanks for any help or a way to find the protocol to allow AppBuilder's app connection.

Last edited by svanneste (2017-01-25 14:40:32)

Offline

#2 2017-01-25 15:49:11

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

Re: Question about WebSockets clients and servers

OK. Found what protocol I have to implement :

The WebSocket handshake (browser request and server response)

GET /text HTTP/1.1\r\n
Upgrade: WebSocket\r\n
Connection: Upgrade\r\n
Host: www.websocket.org\r\n
…\r\n

HTTP/1.1 101 WebSocket Protocol Handshake\r\n
Upgrade: WebSocket\r\n
Connection: Upgrade\r\n
…\r\n

source:  http://websocket.org/quantum.html


I will try to apply that plugin too : https://github.com/blocshop/sockets-for-cordova

Last edited by svanneste (2017-01-25 16:32:57)

Offline

#3 2017-01-25 16:58:52

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: Question about WebSockets clients and servers

Hello Samuel,

I must honestly admit that my knowledge abot websockets is very limited, in particular the server side stuff. I implement the client side in App Builder because for sure websockets can be useful, that is, to maintain a connection between the application and the application's server so far than made "simply" HTTP calls.

In principle both the client side and server side must implement the HTML5 WebSocket. This is done in App Builder (for the client side) but the server is enterely out of the scope of App Builder, and, as you probably know, the WebSocket application sample uses the "echo websocket" server provided by "ws://echo.websocket.org".

So please, Samuel, just let me know if you need some help or addition in the client side in order to get your application working.

Offline

#4 2017-01-25 17:05:57

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: Question about WebSockets clients and servers

Hello again,

One more thing Samuel: I am not sure if we need here the refered Apache Cordova's plugin... probably the WebSocket controls is enough, or I am completely wrong...?

Offline

#5 2017-01-25 17:11:05

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

Re: Question about WebSockets clients and servers

Hello David,
Thanks for your replies. You are right, we don't need the pure TCP socket plugin here (this was just a workaround for me).

What I am currently have to code is the server's part (the one which will reply to AppBuilder's app to let it know it is connected).  I am on.

Many thanks smile

Last edited by svanneste (2017-01-25 17:11:38)

Offline

#6 2017-01-25 17:15:08

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: Question about WebSockets clients and servers

Hello Samuel,

If we are talking about a PHP implementation of a Websockets, then for sure I can help you at least by pointing to some useful resources. Since I imagine that we are not talking about Apache nor PHP here... I am here at your service if you need any other kind of help, for example, to perform some tests. smile

Offline

#7 2017-01-25 22:57:49

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

Re: Question about WebSockets clients and servers

Just a question, David, please. Should I be able to find the reply AppBuilder is waiting, in the JavaScript Editor ? Thanks

Last edited by svanneste (2017-01-25 22:58:14)

Offline

#8 2017-01-25 23:04:08

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: Question about WebSockets clients and servers

Hello Samuel,

I am not sure if understand well. Once we call the "SocketOpen" action, we are "waiting"... for the WebSocket control's Open event to be fired. Is something like that you need? That is, for example, we can use the SocketOpen action, then show a Progressbar control, and, hide it on the Websocket control's Open or other event like Error...

Can this help you in some way?

Offline

#9 2017-01-25 23:06:53

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

Re: Question about WebSockets clients and servers

Nope David,
In the JavaScript Editor, when I search for "Socket", I find some Javascript related functions.
Because I have some trouble returning the data, AppBuilder is waiting before to fire the Open event, I was asking if, in that code, I can find the type of data it is waiting for.

Many thanks

Last edited by svanneste (2017-01-25 23:07:14)

Offline

#10 2017-01-25 23:12:00

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: Question about WebSockets clients and servers

Hello Samuel,

Because I have some trouble returning the data, AppBuilder is waiting before to fire the Open event, I was asking if, in that code, I can find the type of data it is waiting for

I am very sorry but can't understand... no doubt by my fault. But I want to try again! What about if you use various WebSockets? In that case you know what WebSocket you are using and what type of data you are waiting for... Have this some sense? Or maybe can you explain me the issue like if I am an eight year old child.... sorry for that Samuel. sad

Offline

#11 2017-01-25 23:17:56

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

Re: Question about WebSockets clients and servers

No problem at all. I can understand that my question is too large. So, please forgive me if my reply seems a bit stupid. Here is the problem :

- I make AppBuilder initiate the WebSocket connection using SocketOpen
- On the server, I get the request (as I posted above)
- Now, I have to send the reply to AppBuilder to make it fire the WebSocket.Open event

I am here and unable to find the correct data I have to return to let AppBuilder know it is connected.

So, I have thought that I could find in the app's JavaScript Editor, the description of the information required (the information I have to return).

Offline

#12 2017-01-25 23:22:17

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: Question about WebSockets clients and servers

Hello Samuel,

Oh, that's right! Now I can understand. Thanks for your patience sir... The problem is I have no experience in Websockets server,  and, the sample application uses a sample one that, apparently, provide the right reply, since the Open event is fired in the expected way.

It's ok Samuel. Let me to investigate a little more about this. My intention is to prepare a WebSocket here in hosting (using Apache and PHP in my case, but I think this no matter now) and then maybe I can tell you a little more about the possible response requeriments.

P.S. I think this question must be answered in the WebSockets HTML5 API documentation... or I am wrong... but anyway let me sometime to investigate about the issue. And please sorry any possible inconveniences.

Offline

#13 2017-01-25 23:24:59

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

Re: Question about WebSockets clients and servers

David wrote:

P.S. I think this question must be answered in the WebSockets HTML5 API documentation...

Hello David,
Please do not spend time on the PHP part, I had not thought to check the HTML5 API documentation (I followed some tutorial about websockets). I am going to the HTML5 part immediately.
Thanks (wishing you a good evening)

Last edited by svanneste (2017-01-25 23:25:28)

Offline

#14 2017-01-25 23:26:46

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: Question about WebSockets clients and servers

Hello Samuel,

svanneste wrote:
David wrote:

P.S. I think this question must be answered in the WebSockets HTML5 API documentation...

Hello David,
Please do not spend time on the PHP part, I had not thought to check the HTML5 API documentation (I followed some tutorial about websockets). I am going to the HTML5 part immediately.
Thanks (wishing you a good evening)

No problem! In fact I want to do it sir. I want to know how a WebSocket server can be setup (in my case with Apache + PHP) and how they can be consumed with the App Builder WebSocket control. I will inform you about any progress on this. smile

Offline

#15 2017-01-26 12:52:15

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: Question about WebSockets clients and servers

Hello Samuel,

Just to say that I start investigating how to setup a websocket server using PHP. The task do not appear as "easy" as I think in principle, that is, apparently it's not only a question to prepare some PHP scripts to give the appropiate response, but, on the contrary, they implied other tasks: to be honest I am not sure how to achieve it right now, so I am not saying they are difficult, I just say that I have no idea right now about how to achieve it.

But I persevere Samuel... the point is that maybe the question must be re-created (at least to me) because, if we have a websocket server running... then their behaviour must be... the expected for a websocket server running... I am not sure if can explain what I want to say. Anyway this is only a post to inform about my progress now... as I say before I will continue investigating about and hope that can prepare a PHP websocket server working... even if maybe this can't help you this time... since you do not use PHP (if I am not wrong)...

More later! smile

Offline

#16 2017-01-26 14:05:51

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: Question about WebSockets clients and servers

Hello Samuel,

I have not very good news... first of all, I continue figuring out how to setup a websockets server with the help of PHP. However, all of what I found can't really help me to achieve that. I definitely have lacks of knowledge about the websockets technology. Apparently the server must support that, so it's not only a question to prepare the appropiate stuff, but the server must support this technology.

Another bad news is that finally I decide to try the WebSocket sample into an Android device, that is, after build the application with Apache Cordova. Unfortunatelly they doesn't work as expected (as they do in the browsers) probably because the Android's Chrome's WebView (used in Cordova) do not support the WebSocket HTML5 API, which is used by the WebSocket control in App Builder.

So in conclusion I have no idea about how to implement a WebSocket server, and, on the other hand, if we want to use it on Android devices (for example) we must use a Cordova's plugin, maybe the plugin you refer above. Certainly WebSockets appear very interesting, but not too well supported nowadays...

Maybe all of the above can help you in some way Samuel, but I think I can also help you if you provide me a sample application (which uses your Websocket server) then maybe I can view here more information about the error and then provide you some additional help about.

Offline

#17 2017-04-28 17:29:49

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: Question about WebSockets clients and servers

Hello Samuel,

Just for your information, here is a little more about WebSockets and PHP. I find this useful article, and, certainly I can get it working using the WebSocket control of App Builder. The problem? Continue to be the same to me: certainly this WebSockets server implementation in PHP works, but, they requires a "server.php" script to be running "alone" and persistently, since they setup the WebSocket. In my opinion, another more elegant solution than this (that on the other hand can be a good sample) may must be found in order to prepare something more usable like maybe the Ratchet project.

That's all for now!

Offline

#18 2017-05-03 12:55:52

svanneste
Member
From: Paris, France
Registered: 2015-05-27
Posts: 155

Re: Question about WebSockets clients and servers

Hello David,
Thanks a lot for the message and the new information. I apologize for the delay (had no machine till now).  smile

Offline

#19 2017-05-03 12:57:22

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: Question about WebSockets clients and servers

Hello Samuel,

No problem! smile

Offline

Board footer

Powered by FluxBB


Copyright ©2018 DecSoft. All rights reserved.