Author | Topic: WebSocketHandler, get adicional info and force disconnect? | |
---|---|---|
Joao Grenhas | WebSocketHandler, get adicional info and force disconnect? on Wed, 01 Mar 2017 16:57:25 +0000 Hello all, I have two questions about the use of WebSocketHandler: 1- Is it possible to get adicional information, for example, the IP address of the client that is connecting? In WebHandler, there is the object :HttpRequest, but in WebSocketHandler there is not (both in documentation and when looking at the WebSocketHandler object) 2- Is it possible to force the disconnect of the connection? I tried :disconnect() (which is only documented in WebSocketClient), but didn't work even if it didn't give an error. Best Regards, | |
Boris Borzic | Re: WebSocketHandler, get adicional info and force disconnect? on Wed, 01 Mar 2017 21:35:25 +0100 Joao Grenhas wrote in news:6efccf2b$6a87c964$13729@news.alaska-software.com: > I have two questions about the use of WebSocketHandler: I don't know about the Xbase++ 2.0 WebSocketHandler, but you can definitely do this with the Xb2.NET WebSocket implementation (works with all versions of Xbase++ 1.82 and up), see: http://Xb2.Net/xb2net/ > 1- Is it possible to get adicional information, for example, the IP > address of the client that is connecting? > In WebHandler, there is the object :HttpRequest, but in > WebSocketHandler there is not (both in documentation and when looking > at the WebSocketHandler object) With Xb2.NET, on the server-side you have access to the client socket: 1. Before it's upgraded to a WebSocket (while it's still an HTTP request). This is provided in the :FilterRequest method, example: FUNCTION FilterRequest( oClient ) if oClient:isWebSocket if xbSocket():InetNtoA(oClient:RemoteAddr) != "10.10.0.222" don't allow WebSocket connection from this location oClient:close() Return .F. endif endif Return .T. 2. After the connection is accepted and upgraded to a WebSocket, you have access to the xbWebSocket instance which is derived from xbSocket (the raw TCP/IP socket) and you can use any method or property available with the base socket class. Here is a code snippet for a server-side WebSocket function (found in the WEBSERVE.PRG sample included with Xb2.NET): PROCEDURE WS_Echo( oSock ) oSock:RecvTimeout(30000) limit amount of data that we will accept from client oSock:MaxPayloadSize := 1000 oSock:Send("We are connected... HIGH FIVE!") oSock:Send("WebSocket server powered by Xb2.NET") if oSock:isSecure() oSock:Send("cipher:" + oSock:GetCurrentCipher(.t.)) endif oSock:Send("Your IP is:" + xbSocket():InetNtoA(oSock:RemoteAddr)) oSock:Send() etc.... > 2- Is it possible to force the disconnect of the connection? > I tried :disconnect() (which is only documented in WebSocketClient), > but didn't work even if it didn't give an error. With Xb2.NET you can use the :Close() and :Destroy() methods to force a disconnect on either the client or server sides. Best regards, Boris Borzic http://xb2.net http://sqlexpress.net industrial strength Xbase++ development tools | |
Frank Grossheinrich | Re: WebSocketHandler, get adicional info and force disconnect? on Fri, 03 Mar 2017 11:04:37 +0100 Joao, Thank you for your questions. Infact you have uncovered an oversight - with the documented interfaces it is not yet possible to initiate a server side websocket disconnection. Furthermore, the availability of the HttpRequest on the webhandler was done in one of the latest Xbase++ updates. We already have plans to make the HttpRequest available on the WebSocketHandler as well - we are looking for a short term solution. Nevertheless, for both issues, please get in contact with Alaska Technical support at support@alaska-software.com. They may provide an intermediate solution. Hope this helps, Frank On 01.03.2017 17:57, Joao Grenhas wrote: > Hello all, > I have two questions about the use of WebSocketHandler: > > 1- Is it possible to get adicional information, for example, the IP address > of the client that is connecting? > In WebHandler, there is the object :HttpRequest, but in WebSocketHandler > there is not (both in documentation and when looking at the > WebSocketHandler > object) > > > 2- Is it possible to force the disconnect of the connection? > I tried :disconnect() (which is only documented in WebSocketClient), but > didn't work even if it didn't give an error. > > Best Regards, |