alec1o / netly Goto Github PK
View Code? Open in Web Editor NEWCross-Platform and Multi-Protocol C# Socket Library. (Extremely fast and easy) ๐ณ ๐ช ๐น ๐ฑ ๐พ
Home Page: https://netly.docs.kezero.com
License: MIT License
Cross-Platform and Multi-Protocol C# Socket Library. (Extremely fast and easy) ๐ณ ๐ช ๐น ๐ฑ ๐พ
Home Page: https://netly.docs.kezero.com
License: MIT License
not work.
I hope Netly can provide a built-in method for obtaining local IP addresses
Originally posted by @1101728133 in #28 (reply in thread)
Is your feature request related to a problem? Please describe.
Update Netly tags, because the package is hard found on nuget by topic search.
Describe the solution you'd like
add websokets and others relevant tags to be found easy on nuget.
e.g: netly
socket
sockets
lib
alec1o
kezero
ws
websocket
websockets
websocket-server
websocket-client
client
server
...
Describe alternatives you've considered
N/A
Additional context
Update tags on src/Netly.csproj
Update nuget readme to contain websocket and http examples.
๐ https://stackoverflow.com/questions/73237486/creating-tcp-connection-and-getting-the-header
Protocols like http detect the framing of your data through the stream, and create the framing at the application level, Netly's function is to provide the socket and optionally contains the framing at the application level since version 3, much more I think netly it should be smart enough to create frames through the headers received by the sender. And that:
Relying on TCP headers to create a "frame" rather than creating a frame based on the data received.
Advantage of application-level framing?
Advantage of framing at socket level?
Resilient (if you can put framing at the socket level, it means all applications communicate without dependency and overhead)
No overhead (This is by sending both and receiving data the libraries do not need to send extra data in the message body to handle framing at the application level.
What am I trying to say with framing?
TCP has a very low data limit and if you want to send 1 megabyte you cannot send it linearly, that is, you need to divide this data and send it in small pieces and the framing function both at the application level and at the socket level is to detect and accumulate the data until it reaches 1 megabytes and only then release it to the receiving target. in case of download, it can be a file on the disk to write to the buffer each time it receives a fragment of data.
Netly by default will use the memory as a buffer, this works well if the data to be received is small, i.e. less than ~10 megabytes, and in case of receiving Gigabytes, Netly will need to use the gigabytes in RAM, and that's where the danger lies. and problem. Netly currently has framing at the application level and has a limit of 8 megabytes that it allows to receive and this can be customized up to as much GB, TB, etc. as you want. The next update to fix this should be to allow netly to write the buffer to disk in a temporary folder and then pass the file path instead of data in a parameter. This can be customized, for example from 10MB. In any case, this is a danger that resides in the framing of any layer,
But being realistic, most users don't even use 1MB, they use it to browse messages and small data and will rarely send large files. In any case, netly being able to deal with framing at the socket level brings compatibility without overhead and with data resilience.
# current version
Host instance = new Host("127.0.0.1", 8080);
Host instance = new Host(...);
# new features required
Host instance = new Host("www.alec1o.com:8080");
Hacks
new Host("www.alec1o.com:7777").RunDNS()
I was looking for a library that supports both tcp and websocket in Unity.
I found it today and wrote code to test websocket.
It works well.
I hope this code is useful to someone who is new to netly.
I'll have to test it in Unity tomorrow.
thank you very much your effort.
Sample WebSocketClient & Sample WebSocketServer
NOTE: all received data are bytes, when bufferType is
HTTP.Text
it means the bytes are text converted to bytes (can be converted to text again), otherwise it means the bytes areBinary
orHTTP.Binary
and data cannot or should not be converted to text format
using System.Text;
using Netly;
namespace SampleWebSocketClient;
class Program
{
static void Main(string[] args)
{
var client = new HTTP.WebSocket();
client.On.Open(() =>
{
Console.WriteLine("client.On.Open");
// send message to server
byte[] send = NE.GetBytes("hello world!", Encoding.UTF8);
client.To.Data(send, HTTP.Binary);
});
client.On.Close(() =>
{
Console.WriteLine("client.On.Close");
});
client.On.Error((exception) =>
{
Console.WriteLine("client.On.Error " + exception.Message);
});
client.On.Data((bytes, bufferType) =>
{
string received = NE.GetString(bytes, Encoding.UTF8);
Console.WriteLine(received);
});
client.On.Event((name, bytes, bufferType) =>
{
// websocket receives Netly event (Only Netly)
// EXAMPLE:
if (name == "client quit")
{
// send event to server
client.To.Event("goodbye", "Some data here", bufferType);
// close connection.
client.To.Close();
}
});
client.On.Modify((ws) =>
{
// modify socket
});
while (true)
{
if (!client.IsOpened)
{
client.To.Open(new Uri("ws://somedomain.com:8888/echo"));
Console.WriteLine("client.To.Open");
// Just Hold the Console
Console.WriteLine("Message: ");
string message = Console.ReadLine();
}
else
{
// Just Hold the Console
Console.WriteLine("Message: ");
string message = Console.ReadLine();
}
}
}
}
using Netly;
namespace SampleWebSocketServer;
class Program
{
static void Main(string[] args)
{
HTTP.Server server = new HTTP.Server();
server.Map.WebSocket("/echo", (request, websocket) => {
websocket.On.Data((bytes, bufferType) =>
{
// echo data.
websocket.To.Data(bytes, bufferType);
});
websocket.On.Event((name, bytes, bufferType) =>
{
// echo event.
websocket.To.Event(name, bytes, bufferType);
});
});
server.On.Open(() =>
{
Console.WriteLine("server.On.Open");
});
server.On.Close(() =>
{
Console.WriteLine("server.On.Close");
});
server.On.Error((exception) =>
{
Console.WriteLine("server.On.Error" + exception.Message);
});
while (true)
{
if (!server.IsOpened)
{
server.To.Open(new Uri("http://somedomain.com:8888"));
}
else
{
// Just Hold the Console
Console.WriteLine("Message: ");
string message = Console.ReadLine();
}
}
}
}
I believe there is bug in the MainThread.Clean method. It removes only half callbacks per one call if there are many callbacks
I used your project in a multiplayer game, and I am very grateful to you. Your project is excellent and very beginner-friendly.Looking forward to your game.
--็ฑๆฅ่ช**
Is your feature request related to a problem? Please describe.
the docs of project is manual and maybe can have errors on api. and is hard mantain manual wrote, for fix that should consider include tools to generate api from sources using XML comments.
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
Additional context
If the choice is DocFx
After many test i find it.
Runnig on Android 11 (same error)
Real Device
Runnig on Android 9 (Android Emulator)MeMu Play
Runnig on Android 9 (Android Emulator)BlueStacks 5
The origin of error is internal and unknow
It's definitely a DOTNET issue on android. Netly uses System.Net.Sockets
as the basis for socket creation. This library is having internal errors in the Android device.
My suspicions:
System.Net.Sockets
internally is not working due to some internal type of conversion (C# to C++/Java or object).Doubts:
The problem is with the TCP server or TcpClient. What about the server that is not working (listening directly?) or the TcpClient that cannot connect to the socket? (Needs to be tested)
In case the problem is the TcpServer that cannot listen to the localhost on Android or the TcpClient that cannot connect to the localhost. How should you solve it if the problem is internal? (Do nothing?)
How to move forward? Continue writing socket using System.Net.*
? or start the base in C++ and the interface in C#?
Originally posted by @alec1o in #33 (comment)
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.