Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Server Development
Habbo Retros
Habbo Q&A
Problems with WebSocket - Plus Emulator
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Cen0n" data-source="post: 442606" data-attributes="member: 63949"><p>Hello, I'm having some problems on my WebSocket, could someone help me solve this?</p><p>The situation is as follows:</p><p></p><p>The connection is usually made when the user enters the client, everything works, but when there is an internet oscillation of the person, the connection closes and is disconnected, even if it oscillates for only 1 second.</p><p></p><p>I was wondering if there is any way to reconnect without being disconnected from the client because all of the interactive functions of the game run through the websocket</p><p></p><p>Connection code below:</p><p>[CODE]</p><p>using Plus;</p><p>using Fleck;</p><p></p><p>namespace WebSocket</p><p>{</p><p> public class WebManager</p><p> {</p><p> public WebSocketServer wsServer;</p><p> public WebManager()</p><p> {</p><p> _clientsBySocket = new ConcurrentDictionary<IWebSocketConnection, int>();</p><p> wsServer = new WebSocketServer("ws://0.0.0.0:3000");</p><p> }</p><p></p><p> private readonly ConcurrentDictionary<IWebSocketConnection, int> _clientsBySocket;</p><p></p><p> public void Init()</p><p> {</p><p> wsServer.Start(ws =></p><p> {</p><p> ws.OnOpen = () => ws.Send("searching");</p><p></p><p> ws.OnMessage = msg =></p><p> {</p><p> if (string.IsNullOrEmpty(msg))</p><p> return;</p><p> var evnt = Regex.Split(msg, "Event")[1];</p><p> var Evnt = evnt.Split('.')[0];</p><p> var name = Regex.Split(msg, "Name")[1];</p><p> var Name = name.Split('.')[0];</p><p> var data = Regex.Split(msg, "Data")[1];</p><p> var Data = data.Split('.')[0];</p><p> var edata = Regex.Split(msg, "ExtraData")[1];</p><p> var ExtraData = edata.Split('.')[0];</p><p> var client = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Name);</p><p> if (Evnt == "search")</p><p> {</p><p> if (client != null && client.GetHabbo() != null && client.GetRolePlay() != null)</p><p> {</p><p> _clientsBySocket[ws] = client.GetHabbo().Id;</p><p> client.GetRolePlay().ws = ws;</p><p> }</p><p> else</p><p> {</p><p> ws.Send("searching");</p><p> }</p><p> }</p><p> else</p><p> {</p><p> client.GetRolePlay().WebHandle(Evnt, Data, ExtraData);</p><p> }</p><p> };</p><p></p><p> ws.OnClose = () =></p><p> {</p><p> if (!_clientsBySocket.TryGetValue(ws, out var clientId)) return;</p><p> var client = PlusEnvironment.GetGame().GetClientManager().GetClientByUserID(clientId);</p><p> if (client.GetRolePlay().ws == null)</p><p> return;</p><p> client.GetRolePlay().ws.Close();</p><p> client.GetRolePlay().ws = null;</p><p> };</p><p> ws.OnError = Exception => ws.Close();</p><p> });</p><p> }</p><p> }</p><p>}[/CODE]</p></blockquote><p></p>
[QUOTE="Cen0n, post: 442606, member: 63949"] Hello, I'm having some problems on my WebSocket, could someone help me solve this? The situation is as follows: The connection is usually made when the user enters the client, everything works, but when there is an internet oscillation of the person, the connection closes and is disconnected, even if it oscillates for only 1 second. I was wondering if there is any way to reconnect without being disconnected from the client because all of the interactive functions of the game run through the websocket Connection code below: [CODE] using Plus; using Fleck; namespace WebSocket { public class WebManager { public WebSocketServer wsServer; public WebManager() { _clientsBySocket = new ConcurrentDictionary<IWebSocketConnection, int>(); wsServer = new WebSocketServer("ws://0.0.0.0:3000"); } private readonly ConcurrentDictionary<IWebSocketConnection, int> _clientsBySocket; public void Init() { wsServer.Start(ws => { ws.OnOpen = () => ws.Send("searching"); ws.OnMessage = msg => { if (string.IsNullOrEmpty(msg)) return; var evnt = Regex.Split(msg, "Event")[1]; var Evnt = evnt.Split('.')[0]; var name = Regex.Split(msg, "Name")[1]; var Name = name.Split('.')[0]; var data = Regex.Split(msg, "Data")[1]; var Data = data.Split('.')[0]; var edata = Regex.Split(msg, "ExtraData")[1]; var ExtraData = edata.Split('.')[0]; var client = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Name); if (Evnt == "search") { if (client != null && client.GetHabbo() != null && client.GetRolePlay() != null) { _clientsBySocket[ws] = client.GetHabbo().Id; client.GetRolePlay().ws = ws; } else { ws.Send("searching"); } } else { client.GetRolePlay().WebHandle(Evnt, Data, ExtraData); } }; ws.OnClose = () => { if (!_clientsBySocket.TryGetValue(ws, out var clientId)) return; var client = PlusEnvironment.GetGame().GetClientManager().GetClientByUserID(clientId); if (client.GetRolePlay().ws == null) return; client.GetRolePlay().ws.Close(); client.GetRolePlay().ws = null; }; ws.OnError = Exception => ws.Close(); }); } } }[/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Q&A
Problems with WebSocket - Plus Emulator
Top