sta / sta/websocket-sharp

Issue with fast reconnection...

Open
#72 19 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
6.1k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

If I connect to my application for the first time, it will properly connect to the socket and listen to it.

However if I connect, close the socket, close my application and then try to connect again it gets stuck at this part:

20/08/2014 16:52:41|Debug|WebSocket.sendHttpRequest|
A request to the server:
    GET /complete?s=3
                HTTP/1.1

                User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0

                Upgrade: websocket
                Connection: Upgrade
                Host: chat.domain.com
                Origin: http://chat.domain.com
                Sec-WebSocket-Key: Xj/iRVe0qIDcCRxEewkd+A==

                Sec-WebSocket-Extensions: permessage-deflate

                Sec-WebSocket-Version: 13

20/08/2014 16:52:41|Debug|WebSocket.sendHttpRequest|
A response to this request: HTTP/1.1 
                101 Switching Protocols
                Upgrade: websocket
                Connection: Upgrade
                Sec-WebSocket-Accept: iHzCwoe416EVEiQ7s2KoPFQhk6Q=

And receive no data regardless of amount of time I let the application open. Then I have to close the application wait a few seconds before starting it again so that it properly connects.

This is the latest version available on git and the only change I ever made was hardcoded a different user agent.

Since it gives me no information about what is going on in this case the websocket will just remain there so I can't use "Using (var ws....)" as I need to close that socket if the OnMessage event is never trigged.

It does trigger the OnOpen event but that is all it does.

So I have to have it like this on my project:

socket = new WebSocket(Url);
socket.OnMessage += (senter, e) => ReceiveData(e.Data);
socket.OnClose += (sender, e) => Reconnect(e.Code, e.Reason);
socket.Log.Level = LogLevel.Trace;
socket.Log.File = Path.Combine(logFolder, "websocket.log");
socket.Compression = CompressionMethod.Deflate;
socket.Origin = origin;
socket.ConnectAsync();

So that I am able to perform:

socket.Close();

But regardless of closing the socket, I can't reconnect to it again not instantiate a new socket as keeps giving me the other errors I have early reported as different issues, as they are.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the connect, close, application restart, and reconnect sequence, then trace WebSocket.sendHttpRequest and the ConnectAsync, OnOpen, OnClose, and Close entry points. Use the logged 101 response and missing subsequent data to identify the stalled state; done means a newly started connection receives data without waiting several seconds.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.