<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Kohji Yamamoto</title>
    <description>The latest articles on Forem by Kohji Yamamoto (@kyamamoto03).</description>
    <link>https://forem.com/kyamamoto03</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F441319%2Fad5c8d92-9591-4df5-8fe0-a2e83fbe9206.jpeg</url>
      <title>Forem: Kohji Yamamoto</title>
      <link>https://forem.com/kyamamoto03</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kyamamoto03"/>
    <language>en</language>
    <item>
      <title>DotNetCore Native Network Framework Sockety</title>
      <dc:creator>Kohji Yamamoto</dc:creator>
      <pubDate>Mon, 27 Jul 2020 03:31:44 +0000</pubDate>
      <link>https://forem.com/kyamamoto03/dotnetcore-native-network-framework-sockety-475</link>
      <guid>https://forem.com/kyamamoto03/dotnetcore-native-network-framework-sockety-475</guid>
      <description>&lt;p&gt;&lt;a href="//README-ja.md"&gt;Japanese Document&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Sockety
&lt;/h1&gt;

&lt;p&gt;It is a network framework written in .NET Core.&lt;br&gt;
It wraps Socket and allows for easy server-client communication.&lt;/p&gt;
&lt;h2&gt;
  
  
  Communication Method.
&lt;/h2&gt;

&lt;p&gt;When a client connects to a server in Sockety, it connects TCP and UDP.&lt;/p&gt;
&lt;h2&gt;
  
  
  Function.
&lt;/h2&gt;

&lt;p&gt;Disconnection detection (internal use)&lt;br&gt;
Client to server communication (with return value from server)&lt;br&gt;
Server to client push communication&lt;br&gt;
Lightweight communication using UDP&lt;br&gt;
Encrypted communication using SSL (TCP only)&lt;br&gt;
UDP communication using AES&lt;br&gt;
Authentication at the time of communication using an authentication token&lt;br&gt;
It is.&lt;br&gt;
&lt;a href="https://qiita.com/k-yamamoto/items/1bc295f83c873921b408"&gt;UDP avoids NAT with HolePunching&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Development History
&lt;/h1&gt;

&lt;p&gt;Net Core, which requires multi-platform communication, and MagicOnion is used for this purpose.&lt;br&gt;
MagicOnion uses gRPC for its communication core and uses native code. &lt;br&gt;
It's not really necessary to run on Windows ARM, but it's for Hololens2.&lt;/p&gt;
&lt;h1&gt;
  
  
  QuickStart
&lt;/h1&gt;

&lt;p&gt;server-side&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int PortNumber = 11000;
//SSL Setting
var serverSetting = new ServerSetting { UseSSL = true }
serverSetting.LoadCertificateFile("++++.pfx", "certPassword");

//Authentication Filter.
var authtificationFilter = new LocalAuthentificationFilter();
serverCore.SocketyFilters.Add(authtificationFilter);

Add(authtificationFilter); //UDP Port Setting
serverCore.InitUDP(11000, 11120);
//Sockety Start
serverCore.Start(localEndPoint: new IPEndPoint(IPAddress.Any, PortNumber);, _stoppingCts: _stoppingCts, parent: this, _serverSetting: serverSetting);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Client.Connect("localhost",11000, "MyApp",this);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Client (calling party) TCP&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;client.Send("Join", Encoding.ASCII.GetBytes($"{DateTime.Now.ToString()}"));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;you can call a method on the server (in this case, Join) and pass in the current time as an argument.&lt;/p&gt;

&lt;p&gt;Server (the one being called) TCP&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public byte[] Join(ClientInfo sendclientInfo,byte[] JoinDate)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The receiving end of the server looks like this&lt;br&gt;
ClientInfo→Source client information&lt;br&gt;
JoinDate→client.Send's second argument&lt;/p&gt;

&lt;p&gt;Client (calling party) UDP&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;client.UdpSend(Encoding.ASCII.GetBytes(DateTime.Now.ToString()));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Server (the called party) UDP&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public void UdpReceive(ClientInfo sender, byte[] obj)
{
    //Broadcasting client data to all clients
    serverCore.BroadCastUDPNoReturn(sender, obj);

    string str = Encoding.ASCII.GetString(obj);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Package.
&lt;/h1&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet add package Sockety
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Get it at&lt;/p&gt;

&lt;h1&gt;
  
  
  Usage.
&lt;/h1&gt;

&lt;p&gt;I will describe the details of how to use it later, but please refer to the Example first.&lt;br&gt;
Sockety (body)&lt;br&gt;
Example/SocketyServer (sample server)&lt;br&gt;
Example/SocketyClient (sample client)&lt;br&gt;
Example/SocketyClientUWP (sample client version)&lt;/p&gt;

&lt;h1&gt;
  
  
  Repositoty
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://github.com/kyamamoto03/Sockety"&gt;Github&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.nuget.org/packages/Sockety/"&gt;Nuget&lt;/a&gt;&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>socket</category>
    </item>
  </channel>
</rss>
