nterry / awesomesockets Goto Github PK
View Code? Open in Web Editor NEWA fast, lightweight, and easy to use socket library for C#.
License: Other
A fast, lightweight, and easy to use socket library for C#.
License: Other
Would it be possible to create an AwesomeSockets .Net Standard 2.0 version? Or does Awesome Socket have runtime specific dependencies?
Stumbled on this library, looks very minimalist (which is great). I think I have a general Idea how to move forward and integrate this into my applications transport layer. That said, I have a few questions.
ISocketModifier, what is it ?
OnConnect / OnDisconnect events. This does not look implemented. I guess, I will need to implement a simple handshake and a heartbeat myself.
Cloud you please give me some example just like:
When I am sending and receiving a lot of bytes, there is a problem with cpu memory,
CPU memory is fully stuffed, a usage of CPU memory is rising high. What should I do to escape it?
here is the server:
ServerSocket = AweSock.TcpListen(14804);
ClientSocket = AweSock.TcpAccept(ServerSocket);
started = true;
byte[] file = File.ReadAllBytes(@"C:\Users\link\Desktop\Screenshot_1.png");
while (started)
{
Buffer outBuf = Buffer.New(file.Length);
Buffer.ClearBuffer(outBuf);
Buffer.Add(outBuf, file);
Buffer.FinalizeBuffer(outBuf);
int bytesSent = AweSock.SendMessage(ServerSocket, outBuf);
Console.WriteLine("Sent");
}
here is the client:
Client = AweSock.TcpConnect("127.0.0.1", 14804);
byte[] file = File.ReadAllBytes(@"C:\Users\link\Desktop\Screenshot_1.png");
while (started)
{
Buffer inBuf = Buffer.New(file.Length);
Tuple<int, EndPoint> received = AweSock.ReceiveMessage(Client, inBuf);
Console.WriteLine("Received");
frames++;
}
endless loop may increase the cpu memory usage, but I need it
error: Package AwesomeSockets 1.4.19 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package AwesomeSockets 1.4.19 supports: net40 (.NETFramework,Version=v4.0)
error: One or more packages are incompatible with .NETCoreApp,Version=v1.1.
Would be great to have a sockets library that works with Core. Not many do yet.
I just started checking out AwesomeSockets, so far so good.
One issue....
I'm attempting to make it so the Server can have multiple clients connected at once... To do that, it has to be constantly checking for new connections... I do that like this....
private ServerClass()
{
ISocket listenSocket = AweSock.TcpListen(14804);
// Create a new thread for listening for connections
new Thread(() =>
{
while (true)
{
ISocket socket = AweSock.TcpAccept(
listenSocket,
SocketCommunicationTypes.NonBlocking,
ConnectionCallBack);
}
}).Start();
}
private Socket ConnectionCallBack(ISocket socket, Exception exception)
{
// Do stuff...
return socket.GetSocket();
}
The issue is when I try to make it NonBlocking & use the callback, it seems to constantly grow in size (until an out of memory exception is thrown). Without the NonBlocking it works fine. Like so...
new Thread(() =>
{
while (true)
{
ISocket socket = AweSock.TcpAccept(
listenSocket);
if(socket != null)
{
ConnectionCallBack(socket, null);
}
}
}).Start();
Maybe I don't see it but is there support for timeout when read data?
Hi,
first of all thank you for sharing your project.
I use Async TCP Socket and i find a trouble in MessageReceiveThread function. If the ProtocolType is tcp, the code call the callback function without the remoteEndPoint argument.
Thanks,
Marco
I have setup example from the main page with a different address (a whois server on port 43) and it runs ok with no exception but I cannot see any of the response data.
This line:
Tuple<int, EndPoint> received = AweSock.ReceiveMessage(server, inBuf);
I look in received inside debugger and cant see any value or byte array to read. Sorry for basic question but I can't figure it out from example. How do I read response?
Hi, I tried to send a string data to a server using AwesomeSockets from a non-AwesomeSockets client (due to Xamarin.Android, code partially copied from Microsoft Docs here).
I actually uses a simple Bit Scrambling algorithm available in Here to scramble the data, still in ASCII though. The server successfully received the string. However, It receives a different string like it was made of Chinese chars.
This is the code I use in client:
string toBeSend = $"{UserName.Text}\0{PointCount.Text}"; // -> "MyName\01280"
string encodedSend = PSWBit6Codec.Encode(toBeSend); // -> "SWeNXVueBc`p"
byte[] byteData = Encoding.ASCII.GetBytes(encodedSend);
sendSocket.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), client);
// -> Send "SWeNXVueBc`p" as byte array
The code I use in server:
Buffer recv = Buffer.New();
Buffer.ClearBuffer(recv);
Tuple<int, EndPoint> recvTuple = receiverSocket.ReceiveMessage(recv);
string recvStr = Buffer.Get<string>(recv); // -> It receives "啐坍䍀牄卌恌"
string recvstrREnc = Encoding.ASCII.GetString(Encoding.UTF8.GetBytes(recvStr)); // -> Produces "???????????"
What did I miss here? is the Buffer class using a specific encoding when trying to get a string?
Would be great to have a basic chat client/server example to get started with.
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.