stackexchange / netgain Goto Github PK
View Code? Open in Web Editor NEWA high performance websocket server library powering Stack Overflow.
License: MIT License
A high performance websocket server library powering Stack Overflow.
License: MIT License
Inside of
NetGain/StackExchange.NetGain/WebSockets/WebSocketsProcessor_RFC6455_13.cs
Is it intended for the ping to be handled with pong.OpCode = WebSocketsFrame.OpCodes.Binary;
I was getting client disconnects because ping was not being responded to with a pong.
I've changed it to OpCodes.Pong;
and it works as expected. Is this a bug or is there something apart of the RFC6455 standard that I'm missing?
The website that I am using to connect to the socket server uses SSL. How can I do this?
I thought you can send as soon as the client connects, so I tried this:
public class ClientHandler : WebSocketsMessageProcessor
{
protected override void OnOpened(WebSocketConnection connection)
{
connection.Send(Context, "hello");
}
}
But the client didn't receive anything. A workaround I found is to have the client initiate the conversation and send whatever I need to send from OnReceive
.
Is there another way to be notified when I can use the connection to talk to the client?
If it makes any difference, I'm using Websocket4Net on the client:
webSocket = new WebSocket("ws://localhost:1234/");
webSocket.Opened += WebSocket_Opened;
webSocket.MessageReceived += WebSocket_MessageReceived;
webSocket.Closed += WebSocket_Closed;
webSocket.Error += WebSocket_Error;
webSocket.Open();
TcpHandler.DefaultMaxIncomingQuota and DefaultMaxOutgoingQuota is really low.
what is the purpose of this limitation ?
doesn't seems like a protocol requirement.
and WebSocketsProcessor_RFC6455_13.cs use TcpHandler.DefaultMaxOutgoingQuota for it's bufferstream.
and cause it to throw a exception in BufferStream.Grow .
should I set a higher DefaultMaxOutgoingQuota ? or remove the limit completely, or set a different default limit for websocket.
Buffer maximum length exceeded (64555 vs 16384)
Exception = System.InvalidOperationException: Buffer maximum length exceeded (64555 vs 16384)
在 StackExchange.NetGain.BufferStream.Grow(Int32 newLength) 位置 E:\repos\project.server\deps\StackExchange.NetGain\BufferStream.cs:行号 74
在 StackExchange.NetGain.BufferStream.Write(Byte[] buffer, Int32 bufferOffset, Int32 count) 位置 E:\repos\project.server\deps\StackExchange.NetGain\BufferStream.cs:行号 109
在 StackExchange.NetGain.WebSockets.WebSocketsProcessor_RFC6455_13.Send(NetContext context, Connection connection, Object message) 位置 E:\repos\project.server\deps\StackExchange.NetGain\WebSockets\WebSocketsProcessor_RFC6455_13.cs:行号 360
在 StackExchange.NetGain.Connection.Send(NetContext context, Object message) 位置 E:\repos\project.server\deps\StackExchange.NetGain\Connection.cs:行号 265
在 StackExchange.NetGain.WebSockets.WebSocketsMessageProcessor.Send(WebSocketConnection connection, Byte[] message) 位置 E:\repos\project.server\deps\StackExchange.NetGain\WebSockets\WebSocketsMessageProcessor.cs:行号 156
Some very basic documentation defining the key features of NetGains would be nice. Looking at the code I see support for HeartBeat (kicking dead connections), an serverside interface for handling disconnections, authentication, and messages. I also see a UserToken, is this some sort of client session? Its hard to tell because none of the methods have comments.
Also maybe a WebApi / MVC serverside demo would be nice
Hi thanks for sharing this library. Is there any plan to support SSL/TLS so we can do wss in a near future ?
I created the news feed websocket in which it send data to socker server every second, meanwhile I send the new post to the server, it seems like receive synchronously. I would like to know if there is any way to make it async to run the process
There is an artificial restriction on sending messages. The RFC6455 says nothing about such size of messages (http://tools.ietf.org/html/rfc6455#section-5.2). In addition, Send does not accept Streams, but only buffers and strings.
It would be polite for the NetGain do not write logs directly to console.
For module with so many abstractions, it is strange that that logging is done through the console.
How can you use this in an ASP.NET site?
Hi,
I found the websocket server can't accept the connection with the subprotocol.
For example: new wsImpl('ws','subprotocol')
So i modify some places in CompleteHandshake in WebSocketsProcessor_RFC6455_13. Basically I have to append Sec-WebSocket-Protocol before complete the handshake.
My question is how can I override this method in my project instead of modifying the source code?
[2018/7/20 updates] My current solution is to modify the CompleteHandshake in WebSocketsProcessor_RFC6455_13.cs
What I've done is to make sure the subprotocol in headers["sec-websocket-protocol"] is valid, if so, append the acceptable subprotocol in the string frame.
Any suggestions?
Thank you.
Sorry if those questions seem trivial. I have not found any documentation.
Can I send the "Username" on open connection ?
Or this is done at OnAuthenticate?
How can distinguish users right from the start ?
Thanks
I'm sending binary data to the server and one request in particular seems to keep tripping this. In ProcessFrame, there is this code:
else
{
if(pendingCount == 0)
{
Process(context, connection, frame.Payload, frame.OpCode);
} else
{
throw new NotImplementedException();
}
}
I've been trying to strip down an example to reproduce it, but not having much luck. I grabbed the raw request as it was logged by NetGain, then sent it through the TcpClient, but that works just fine. The big difference is the client side is using WebSocket-Sharp. I've pulled in the source code and can see it happen, but since I'm not really that familiar with the protocol it's hard for me to understand what/why it's happening. If it matters, the message is 1035 bytes long. What's interesting is that it says 1036 bytes are available?
But what I see in the Output Window is this:
[server] Receive, Success: 1035 bytes
Received: (1035 bytes are here)
[server] processing with 1036 bytes available
Parsed header from: 02-FE-03-F8-78-E2-56-B7
[server] processed 1024 bytes; 12 remaining
[server] processing with 12 bytes available
BTW - Is there an easy way to actually view the activity when the client isn't a browser? I could do this with Wireshark but then I'd have to move the server to another machine/VM for testing. I'd rather not if there was some nice way of doing it.
with all crazy performance improvements on .net core 2.0 and 2.1, are there any short term plans to migrate to .net core?
Hi,
Are there any planes on supporting ASP.NET Core in this library?
It's specially important since SignalR was pushed off V1.0.
I just fiddled yesterday for couple of hours with WebSockets in ASP.NET Core, and though they were pushed away from Nuget.org to MyGet.org, I managed to integrate WebSockets into a real world ASP.NET Core application.
I'm not sure if I doing something wrong or this just isn't working. Inside of the Console app included in the source, I added this code:
Console.WriteLine("Server running");
// Send ourselves a message
byte[] data = new byte[2] { 0x10, 0x20 };
using (var client = new TcpClient())
{
client.ProtocolFactory = WebSocketClientFactory.Default;
client.Open(new IPEndPoint(IPAddress.Loopback, 6002));
var response = client.ExecuteSync(data);
}
When I run it and set a breakpoint on the received event, nothing is in the Value property. I am supposed to do something else here?
Is there anyway to send messages by a group? For example, track user ID and send to all sockets that are connected with that ID?
The following code will reproduce the bug.
var endpoint = new IPEndPoint(IPAddress.Loopback, 6002);
using (var client = new TcpClient()) {
client.ProtocolFactory = WebSocketClientFactory.Default;
client.Open(endpoint);
var dataLength = 4096;
var bytes = new byte[dataLength];
var resp = (string)client.ExecuteSync(bytes);
WriteLine($"{DateTime.Now:HH:mm:ss fff}\t{resp}");
}
I think there must be something wrong in method: BufferStream.Write(byte[] buffer, int bufferOffset, int count)
.
int origCount = count;
CheckDisposed();
if(isReadOnly) throw new NotSupportedException();
int newEnd = checked((offset - origin) + count);
if (newEnd > length)
{
Grow(newEnd);
length = newEnd;
}
int chunkIndex = offset/NetContext.BufferSize, chunkOffet = offset%NetContext.BufferSize;
int thisPage = NetContext.BufferSize - chunkOffet;
var chunk = buffers[chunkIndex]; // will throw ArgumentOutOfRangeException if the buffer.Length == 4096
if (thisPage >= count)
{
// can write to a single page
Buffer.BlockCopy(buffer, bufferOffset, chunk, chunkOffet, count);
}
Hi,
I've managed to implement NetGain as a complete replacement for Websocket-sharp for my mobile MMO game, it seems to completely work without any issues, but with Websocket-sharp, there were some packets that I was sending to clients that were none async - I need to guarantee order in these packets. I noticed that the TcpHandler sends all messages using the Socket.SendAsync method and I can't seem to find anything that handles orderering of packets being sent or waiting for an async send to complete before moving onto the next - I'm hoping I'm wrong though. Please can you confirm if guaranteed ordering of sends is implemented in some way?
Alternatively, would there be any sideeffects if I were to implement the Socket.Send method?
Many thanks,
Daryl
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.