.NETヘルプ Supersocket C#の例(開発者向けの動作方法) Curtis Chau 更新日:7月 28, 2025 Download IronPDF NuGet Download テキストの検索と置換 テキストと画像のスタンプ Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article SuperSocketとIronPDFを統合したサーバーサイドソケットアプリケーションの開発 SuperSocket C#は、GPSサーバーや工業用制御システムの開発において、サーバーサイドのソケットアプリケーションを開発するための優れたフレームワークです。 さまざまなネットワークプロトコルの実装をサポートし、ソケットが効率的に動作することを保証します。 この軽量なクロスプラットフォームのフレームワークは拡張可能な設計となっており、さまざまな環境に柔軟に対応できます。 SuperSocketを使用すると、クライアントとサーバー間で簡単にデータを送信でき、ソースコードはプロジェクトの特定の要件に合わせてカスタマイズ可能です。 オープンソースのフレームワークなので、開発者は誰でもGitHubを通じて実装し、アクセスできます。 IronPDFは、PDFドキュメントの作成、編集、内容の抽出のための強力な.NETライブラリです。 アプリケーションにPDF機能を統合する必要がある開発者向けに設計されています。 IronPDFは、HTMLからPDFを生成することや、PDFのマージ、PDFからのテキストや画像の抽出などのさまざまな機能をサポートしています。 SuperSocketとIronPDFを組み合わせることで、複雑なサーバーサイドアプリケーションを強化できます。 これらは、現代の.NET開発者のニーズを満たすための幅広い機能を提供します。 これらのライブラリは、リアルタイムチャットアプリケーションが必要なデータ収集サーバーや堅牢なゲームサーバーの構築に最適です。 SuperSocket C#の開始方法 .NETプロジェクトにSuperSocket C#を設定する SuperSocket C#を使用し始めるには、.NETプロジェクトを設定する必要があります。 まず、SuperSocket NuGetパッケージをインストールします。 Visual Studioでプロジェクトを開き、パッケージマネージャーコンソールで次のコマンドを実行します。 Install-Package SuperSocket インストールが完了したら、サーバーインスタンスを構成できます。 appsettings.jsonという名前の新しい設定ファイルを作成します。 このファイルは、リスナーやプロトコルを含むサーバー設定を定義します。 { "serverOptions": { "name": "SuperSocketServer", "listeners": [ { "ip": "Any", "port": 4040 } ] } } 次に、サーバーを構成するためのクラスを作成します。 このクラスはappsettings.jsonから設定を読み取り、サーバーインスタンスを初期化します。 using Microsoft.Extensions.Configuration; using SuperSocket; using SuperSocket.Server; public class ServerConfig { public async Task Configure() { var host = SuperSocketHostBuilder.Create() .UseTcpServer() .UseSession<YourSession>() .ConfigureAppConfiguration((hostCtx, configApp) => { configApp.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); }) .Build(); await host.RunAsync(); } } using Microsoft.Extensions.Configuration; using SuperSocket; using SuperSocket.Server; public class ServerConfig { public async Task Configure() { var host = SuperSocketHostBuilder.Create() .UseTcpServer() .UseSession<YourSession>() .ConfigureAppConfiguration((hostCtx, configApp) => { configApp.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); }) .Build(); await host.RunAsync(); } } Imports Microsoft.Extensions.Configuration Imports SuperSocket Imports SuperSocket.Server Public Class ServerConfig Public Async Function Configure() As Task Dim host = SuperSocketHostBuilder.Create().UseTcpServer().UseSession(Of YourSession)().ConfigureAppConfiguration(Sub(hostCtx, configApp) configApp.AddJsonFile("appsettings.json", [optional]:= False, reloadOnChange:= True) End Sub).Build() Await host.RunAsync() End Function End Class $vbLabelText $csharpLabel 基本的なSuperSocket C# の例 SuperSocket C#アプリケーションの基本的な例を見てみましょう。 この例は、受信したデータを返す簡単なエコーサーバーを作成する方法を示します。 まず、セッションクラスを定義します。 このクラスはソケット接続を処理し、データ通信を管理します。 using SuperSocket; public class EchoSession : AppSession { protected override async ValueTask OnSessionStartedAsync() { await base.OnSessionStartedAsync(); Console.WriteLine("New session started."); } protected override async ValueTask OnSessionClosedAsync(CloseEventArgs e) { await base.OnSessionClosedAsync(e); Console.WriteLine("Session closed."); } protected override async ValueTask OnPackageReceivedAsync(ReadOnlyMemory<byte> package) { await SendAsync(package); } } using SuperSocket; public class EchoSession : AppSession { protected override async ValueTask OnSessionStartedAsync() { await base.OnSessionStartedAsync(); Console.WriteLine("New session started."); } protected override async ValueTask OnSessionClosedAsync(CloseEventArgs e) { await base.OnSessionClosedAsync(e); Console.WriteLine("Session closed."); } protected override async ValueTask OnPackageReceivedAsync(ReadOnlyMemory<byte> package) { await SendAsync(package); } } Imports SuperSocket Public Class EchoSession Inherits AppSession Protected Overrides Async Function OnSessionStartedAsync() As ValueTask Await MyBase.OnSessionStartedAsync() Console.WriteLine("New session started.") End Function Protected Overrides Async Function OnSessionClosedAsync(ByVal e As CloseEventArgs) As ValueTask Await MyBase.OnSessionClosedAsync(e) Console.WriteLine("Session closed.") End Function Protected Overrides Async Function OnPackageReceivedAsync(ByVal package As ReadOnlyMemory(Of Byte)) As ValueTask Await SendAsync(package) End Function End Class $vbLabelText $csharpLabel 次に、エコーセッションと共にサーバーを構成し、実行します。 using Microsoft.Extensions.Configuration; using SuperSocket; using SuperSocket.Server; public class EchoServer { public static async Task Main(string[] args) { var host = SuperSocketHostBuilder.Create() .UseTcpServer() .UseSession<EchoSession>() .ConfigureAppConfiguration((hostCtx, configApp) => { configApp.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); }) .Build(); await host.RunAsync(); } } using Microsoft.Extensions.Configuration; using SuperSocket; using SuperSocket.Server; public class EchoServer { public static async Task Main(string[] args) { var host = SuperSocketHostBuilder.Create() .UseTcpServer() .UseSession<EchoSession>() .ConfigureAppConfiguration((hostCtx, configApp) => { configApp.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); }) .Build(); await host.RunAsync(); } } Imports Microsoft.Extensions.Configuration Imports SuperSocket Imports SuperSocket.Server Public Class EchoServer Public Shared Async Function Main(ByVal args() As String) As Task Dim host = SuperSocketHostBuilder.Create().UseTcpServer().UseSession(Of EchoSession)().ConfigureAppConfiguration(Sub(hostCtx, configApp) configApp.AddJsonFile("appsettings.json", [optional]:= False, reloadOnChange:= True) End Sub).Build() Await host.RunAsync() End Function End Class $vbLabelText $csharpLabel この例は、SuperSocket C#を使用して簡単なエコーサーバーを作成する方法を示しています。 サーバーは接続を待ち受け、受信したデータをエコーします。 SuperSocket C#の機能の実装 複数リスナーの処理 SuperSocket C#は複数のリスナーをサポートしており、サーバーが異なるプロトコルやポートを処理することができます。 この機能は、データ収集サーバーやGPSサーバーなどの多用途なアプリケーションの作成に役立ちます。 まず、appsettings.jsonを更新して複数のリスナーを含めます。 { "serverOptions": { "name": "MultiListenerServer", "listeners": [ { "ip": "Any", "port": 4040 }, { "ip": "Any", "port": 5050 } ] } } 次に、これらのリスナーを使用するようにサーバーを構成します。 using Microsoft.Extensions.Configuration; using SuperSocket; using SuperSocket.Server; public class MultiListenerServer { public static async Task Main(string[] args) { var host = SuperSocketHostBuilder.Create() .UseTcpServer() .UseSession<YourSession>() .ConfigureAppConfiguration((hostCtx, configApp) => { configApp.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); }) .Build(); await host.RunAsync(); } } using Microsoft.Extensions.Configuration; using SuperSocket; using SuperSocket.Server; public class MultiListenerServer { public static async Task Main(string[] args) { var host = SuperSocketHostBuilder.Create() .UseTcpServer() .UseSession<YourSession>() .ConfigureAppConfiguration((hostCtx, configApp) => { configApp.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); }) .Build(); await host.RunAsync(); } } Imports Microsoft.Extensions.Configuration Imports SuperSocket Imports SuperSocket.Server Public Class MultiListenerServer Public Shared Async Function Main(ByVal args() As String) As Task Dim host = SuperSocketHostBuilder.Create().UseTcpServer().UseSession(Of YourSession)().ConfigureAppConfiguration(Sub(hostCtx, configApp) configApp.AddJsonFile("appsettings.json", [optional]:= False, reloadOnChange:= True) End Sub).Build() Await host.RunAsync() End Function End Class $vbLabelText $csharpLabel この設定により、サーバーはポート4040と5050の両方で接続を処理することができます。この能力は、さまざまなネットワークプロトコルを管理する必要があるアプリケーションにとって重要です。 バイナリデータ処理の実装 SuperSocket C#はバイナリデータの処理に効率的です。 これは、産業用制御システムなどのバイナリレベルの互換性が必要なアプリケーションにとって重要です。 まず、バイナリデータを処理するセッションクラスを定義します。 using System; using SuperSocket; public class BinaryDataSession : AppSession { protected override async ValueTask OnPackageReceivedAsync(ReadOnlyMemory<byte> package) { var data = package.ToArray(); Console.WriteLine("Received binary data: " + BitConverter.ToString(data)); await SendAsync(data); } } using System; using SuperSocket; public class BinaryDataSession : AppSession { protected override async ValueTask OnPackageReceivedAsync(ReadOnlyMemory<byte> package) { var data = package.ToArray(); Console.WriteLine("Received binary data: " + BitConverter.ToString(data)); await SendAsync(data); } } Imports System Imports SuperSocket Public Class BinaryDataSession Inherits AppSession Protected Overrides Async Function OnPackageReceivedAsync(ByVal package As ReadOnlyMemory(Of Byte)) As ValueTask Dim data = package.ToArray() Console.WriteLine("Received binary data: " & BitConverter.ToString(data)) Await SendAsync(data) End Function End Class $vbLabelText $csharpLabel 次に、バイナリデータセッションと共にサーバーを構成し、実行します。 using Microsoft.Extensions.Configuration; using SuperSocket; using SuperSocket.Server; public class BinaryDataServer { public static async Task Main(string[] args) { var host = SuperSocketHostBuilder.Create() .UseTcpServer() .UseSession<BinaryDataSession>() .ConfigureAppConfiguration((hostCtx, configApp) => { configApp.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); }) .Build(); await host.RunAsync(); } } using Microsoft.Extensions.Configuration; using SuperSocket; using SuperSocket.Server; public class BinaryDataServer { public static async Task Main(string[] args) { var host = SuperSocketHostBuilder.Create() .UseTcpServer() .UseSession<BinaryDataSession>() .ConfigureAppConfiguration((hostCtx, configApp) => { configApp.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); }) .Build(); await host.RunAsync(); } } Imports Microsoft.Extensions.Configuration Imports SuperSocket Imports SuperSocket.Server Public Class BinaryDataServer Public Shared Async Function Main(ByVal args() As String) As Task Dim host = SuperSocketHostBuilder.Create().UseTcpServer().UseSession(Of BinaryDataSession)().ConfigureAppConfiguration(Sub(hostCtx, configApp) configApp.AddJsonFile("appsettings.json", [optional]:= False, reloadOnChange:= True) End Sub).Build() Await host.RunAsync() End Function End Class $vbLabelText $csharpLabel この例は、SuperSocket C#を使用してバイナリデータを受信および送信する方法を示しています。 これは、バイナリプロトコルを処理する必要がある高性能なアプリケーションに役立ちます。 ソケット接続の管理 ソケット接続を維持することは、信頼性のある通信を確保するために重要です。 SuperSocket C#は、このプロセスを簡略化します。 まず、ソケット接続を管理するセッションクラスを定義します。 using SuperSocket; public class ConnectionSession : AppSession { protected override async ValueTask OnSessionStartedAsync() { await base.OnSessionStartedAsync(); Console.WriteLine("Connection started."); } protected override async ValueTask OnSessionClosedAsync(CloseEventArgs e) { await base.OnSessionClosedAsync(e); Console.WriteLine("Connection closed."); } protected override async ValueTask OnPackageReceivedAsync(ReadOnlyMemory<byte> package) { await SendAsync(package); } } using SuperSocket; public class ConnectionSession : AppSession { protected override async ValueTask OnSessionStartedAsync() { await base.OnSessionStartedAsync(); Console.WriteLine("Connection started."); } protected override async ValueTask OnSessionClosedAsync(CloseEventArgs e) { await base.OnSessionClosedAsync(e); Console.WriteLine("Connection closed."); } protected override async ValueTask OnPackageReceivedAsync(ReadOnlyMemory<byte> package) { await SendAsync(package); } } Imports SuperSocket Public Class ConnectionSession Inherits AppSession Protected Overrides Async Function OnSessionStartedAsync() As ValueTask Await MyBase.OnSessionStartedAsync() Console.WriteLine("Connection started.") End Function Protected Overrides Async Function OnSessionClosedAsync(ByVal e As CloseEventArgs) As ValueTask Await MyBase.OnSessionClosedAsync(e) Console.WriteLine("Connection closed.") End Function Protected Overrides Async Function OnPackageReceivedAsync(ByVal package As ReadOnlyMemory(Of Byte)) As ValueTask Await SendAsync(package) End Function End Class $vbLabelText $csharpLabel 次に、接続セッションと共にサーバーを構成し、実行します。 using Microsoft.Extensions.Configuration; using SuperSocket; using SuperSocket.Server; public class ConnectionServer { public static async Task Main(string[] args) { var host = SuperSocketHostBuilder.Create() .UseTcpServer() .UseSession<ConnectionSession>() .ConfigureAppConfiguration((hostCtx, configApp) => { configApp.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); }) .Build(); await host.RunAsync(); } } using Microsoft.Extensions.Configuration; using SuperSocket; using SuperSocket.Server; public class ConnectionServer { public static async Task Main(string[] args) { var host = SuperSocketHostBuilder.Create() .UseTcpServer() .UseSession<ConnectionSession>() .ConfigureAppConfiguration((hostCtx, configApp) => { configApp.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); }) .Build(); await host.RunAsync(); } } Imports Microsoft.Extensions.Configuration Imports SuperSocket Imports SuperSocket.Server Public Class ConnectionServer Public Shared Async Function Main(ByVal args() As String) As Task Dim host = SuperSocketHostBuilder.Create().UseTcpServer().UseSession(Of ConnectionSession)().ConfigureAppConfiguration(Sub(hostCtx, configApp) configApp.AddJsonFile("appsettings.json", [optional]:= False, reloadOnChange:= True) End Sub).Build() Await host.RunAsync() End Function End Class $vbLabelText $csharpLabel この設定により、ソケット接続を管理し、サーバーの堅牢性と信頼性を保証します。 コマンドラインサーバーの作成 SuperSocket C#はコマンドラインサーバーの作成をサポートしています。 この機能は、シンプルなテキストベースのプロトコルを必要とするアプリケーションに役立ちます。 まず、テキストコマンドを処理するコマンドクラスを定義します。 using System.Text; using System.Threading.Tasks; using SuperSocket.Command; using SuperSocket.ProtoBase; public class MyCommand : IAsyncCommand<AppSession, StringPackageInfo> { public async ValueTask ExecuteAsync(AppSession session, StringPackageInfo package) { var commandKey = package.Key; var parameters = package.Parameters; await session.SendAsync(Encoding.UTF8.GetBytes($"You said: {string.Join(' ', parameters)}")); } } using System.Text; using System.Threading.Tasks; using SuperSocket.Command; using SuperSocket.ProtoBase; public class MyCommand : IAsyncCommand<AppSession, StringPackageInfo> { public async ValueTask ExecuteAsync(AppSession session, StringPackageInfo package) { var commandKey = package.Key; var parameters = package.Parameters; await session.SendAsync(Encoding.UTF8.GetBytes($"You said: {string.Join(' ', parameters)}")); } } Imports System.Text Imports System.Threading.Tasks Imports SuperSocket.Command Imports SuperSocket.ProtoBase Public Class MyCommand Implements IAsyncCommand(Of AppSession, StringPackageInfo) Public Async Function ExecuteAsync(ByVal session As AppSession, ByVal package As StringPackageInfo) As ValueTask Dim commandKey = package.Key Dim parameters = package.Parameters Await session.SendAsync(Encoding.UTF8.GetBytes($"You said: {String.Join(" "c, parameters)}")) End Function End Class $vbLabelText $csharpLabel 次に、サーバーをそのコマンドを使用するように構成します。 using Microsoft.Extensions.Configuration; using SuperSocket; using SuperSocket.Command; using SuperSocket.ProtoBase; using SuperSocket.Server; public class CommandLineServer { public static async Task Main(string[] args) { var host = SuperSocketHostBuilder.Create() .UseTcpServer() .UseSession<AppSession>() .UseCommand<StringPackageParser>() .AddCommand<MyCommand>() .ConfigureAppConfiguration((hostCtx, configApp) => { configApp.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); }) .Build(); await host.RunAsync(); } } using Microsoft.Extensions.Configuration; using SuperSocket; using SuperSocket.Command; using SuperSocket.ProtoBase; using SuperSocket.Server; public class CommandLineServer { public static async Task Main(string[] args) { var host = SuperSocketHostBuilder.Create() .UseTcpServer() .UseSession<AppSession>() .UseCommand<StringPackageParser>() .AddCommand<MyCommand>() .ConfigureAppConfiguration((hostCtx, configApp) => { configApp.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); }) .Build(); await host.RunAsync(); } } Imports Microsoft.Extensions.Configuration Imports SuperSocket Imports SuperSocket.Command Imports SuperSocket.ProtoBase Imports SuperSocket.Server Public Class CommandLineServer Public Shared Async Function Main(ByVal args() As String) As Task Dim host = SuperSocketHostBuilder.Create().UseTcpServer().UseSession(Of AppSession)().UseCommand(Of StringPackageParser)().AddCommand(Of MyCommand)().ConfigureAppConfiguration(Sub(hostCtx, configApp) configApp.AddJsonFile("appsettings.json", [optional]:= False, reloadOnChange:= True) End Sub).Build() Await host.RunAsync() End Function End Class $vbLabelText $csharpLabel この例は、SuperSocket C#を使用して簡単なコマンドラインサーバーを作成する方法を示しています。 これは、軽量なテキストベースのプロトコルに最適です。 Integrating SuperSocket C# with IronPDF C#アプリケーションにおいて、IronPDFをSuperSocketと統合することで、特にPDFファイルの処理においてサーバーの能力を大幅に向上させることができます。 この2つの強力なライブラリを効果的に統合する方法を探ってみましょう。 IronPDFの紹介 IronPDF .NETライブラリは、PDFドキュメントの作成、編集、および内容の抽出のための多用途な.NETライブラリです。 レポートや請求書、その他のPDFベースのドキュメントを生成する必要がある場合、IronPDFはこれらのタスクを達成するための使いやすいAPIを提供します。 その主な特徴は、HTMLからPDFへの変換機能です。 PDFの仕様の複雑さに対処することなく、アプリケーションにPDF機能を組み込みたい開発者にとっては素晴らしいツールです。 IronPDF は HTML から PDF への変換に秀でており、元のレイアウトとスタイルを正確に保存します。 これは、レポート、請求書、ドキュメントなどの Web ベースのコンテンツから PDF を作成するのに最適です。 HTML ファイル、URL、または生の HTML 文字列のサポートにより、IronPDF は高品質な PDF ドキュメントを簡単に生成します。 using IronPdf; class Program { static void Main(string[] args) { var renderer = new ChromePdfRenderer(); // 1. Convert HTML String to PDF var htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>"; var pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent); pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf"); // 2. Convert HTML File to PDF var htmlFilePath = "path_to_your_html_file.html"; // Specify the path to your HTML file var pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath); pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf"); // 3. Convert URL to PDF var url = "http://ironpdf.com"; // Specify the URL var pdfFromUrl = renderer.RenderUrlAsPdf(url); pdfFromUrl.SaveAs("URLToPDF.pdf"); } } using IronPdf; class Program { static void Main(string[] args) { var renderer = new ChromePdfRenderer(); // 1. Convert HTML String to PDF var htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>"; var pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent); pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf"); // 2. Convert HTML File to PDF var htmlFilePath = "path_to_your_html_file.html"; // Specify the path to your HTML file var pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath); pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf"); // 3. Convert URL to PDF var url = "http://ironpdf.com"; // Specify the URL var pdfFromUrl = renderer.RenderUrlAsPdf(url); pdfFromUrl.SaveAs("URLToPDF.pdf"); } } Imports IronPdf Friend Class Program Shared Sub Main(ByVal args() As String) Dim renderer = New ChromePdfRenderer() ' 1. Convert HTML String to PDF Dim htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>" Dim pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent) pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf") ' 2. Convert HTML File to PDF Dim htmlFilePath = "path_to_your_html_file.html" ' Specify the path to your HTML file Dim pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath) pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf") ' 3. Convert URL to PDF Dim url = "http://ironpdf.com" ' Specify the URL Dim pdfFromUrl = renderer.RenderUrlAsPdf(url) pdfFromUrl.SaveAs("URLToPDF.pdf") End Sub End Class $vbLabelText $csharpLabel IronPDFをSuperSocket C#とマージするユースケース SuperSocketで構築されたサーバーが、動的にPDFドキュメントを生成して送信するクライアントの要求を処理する必要があると想像してください。 IronPDFを統合することで、サーバーはこれらの要求を処理し、リアルタイムでPDFを生成してクライアントにシームレスに送信できます。 ユースケースのコード例 IronPDFとSuperSocketを統合する方法を示す完全なコード例です。 この例では、クライアント接続を待ち受け、PDFの生成要求を処理し、生成されたPDFをクライアントに返す簡単なSuperSocketサーバーをセットアップします。 using System; using System.Net; using System.Text; using IronPdf; using SuperSocket.SocketBase; using SuperSocket.SocketBase.Protocol; namespace SuperSocketIronPDFExample { class Program { static void Main(string[] args) { var appServer = new AppServer(); var serverConfig = new SuperSocket.SocketBase.Config.ServerConfig { Name = "SuperSocketServer", Ip = "Any", Port = 2012, Mode = SuperSocket.SocketBase.SocketMode.Tcp, MaxConnectionNumber = 100, }; if (!appServer.Setup(serverConfig)) { Console.WriteLine("Failed to set up!"); return; } appServer.NewSessionConnected += NewSessionConnected; appServer.NewRequestReceived += (session, requestInfo) => { if (requestInfo.Key == "GENPDF") { var pdfDocument = CreatePdfDocument(requestInfo.Body); var pdfBytes = pdfDocument.BinaryData; session.Send(pdfBytes, 0, pdfBytes.Length); Console.WriteLine("PDF document sent to client."); } }; if (!appServer.Start()) { Console.WriteLine("Failed to start!"); return; } Console.WriteLine("Server is running. Press any key to stop..."); Console.ReadKey(); appServer.Stop(); } private static PdfDocument CreatePdfDocument(string content) { var pdfRenderer = new ChromePdfRenderer(); var pdfDocument = pdfRenderer.RenderHtmlAsPdf(content); return pdfDocument; } private static void NewSessionConnected(AppSession session) { Console.WriteLine($"New session connected: {session.SessionID}"); } } public class AppServer : AppServer<AppSession, StringRequestInfo> { } public class AppSession : AppSession<AppSession, StringRequestInfo> { } } using System; using System.Net; using System.Text; using IronPdf; using SuperSocket.SocketBase; using SuperSocket.SocketBase.Protocol; namespace SuperSocketIronPDFExample { class Program { static void Main(string[] args) { var appServer = new AppServer(); var serverConfig = new SuperSocket.SocketBase.Config.ServerConfig { Name = "SuperSocketServer", Ip = "Any", Port = 2012, Mode = SuperSocket.SocketBase.SocketMode.Tcp, MaxConnectionNumber = 100, }; if (!appServer.Setup(serverConfig)) { Console.WriteLine("Failed to set up!"); return; } appServer.NewSessionConnected += NewSessionConnected; appServer.NewRequestReceived += (session, requestInfo) => { if (requestInfo.Key == "GENPDF") { var pdfDocument = CreatePdfDocument(requestInfo.Body); var pdfBytes = pdfDocument.BinaryData; session.Send(pdfBytes, 0, pdfBytes.Length); Console.WriteLine("PDF document sent to client."); } }; if (!appServer.Start()) { Console.WriteLine("Failed to start!"); return; } Console.WriteLine("Server is running. Press any key to stop..."); Console.ReadKey(); appServer.Stop(); } private static PdfDocument CreatePdfDocument(string content) { var pdfRenderer = new ChromePdfRenderer(); var pdfDocument = pdfRenderer.RenderHtmlAsPdf(content); return pdfDocument; } private static void NewSessionConnected(AppSession session) { Console.WriteLine($"New session connected: {session.SessionID}"); } } public class AppServer : AppServer<AppSession, StringRequestInfo> { } public class AppSession : AppSession<AppSession, StringRequestInfo> { } } Imports System Imports System.Net Imports System.Text Imports IronPdf Imports SuperSocket.SocketBase Imports SuperSocket.SocketBase.Protocol Namespace SuperSocketIronPDFExample Friend Class Program Shared Sub Main(ByVal args() As String) Dim appServer As New AppServer() Dim serverConfig = New SuperSocket.SocketBase.Config.ServerConfig With { .Name = "SuperSocketServer", .Ip = "Any", .Port = 2012, .Mode = SuperSocket.SocketBase.SocketMode.Tcp, .MaxConnectionNumber = 100 } If Not appServer.Setup(serverConfig) Then Console.WriteLine("Failed to set up!") Return End If AddHandler appServer.NewSessionConnected, AddressOf NewSessionConnected AddHandler appServer.NewRequestReceived, Sub(session, requestInfo) If requestInfo.Key = "GENPDF" Then Dim pdfDocument = CreatePdfDocument(requestInfo.Body) Dim pdfBytes = pdfDocument.BinaryData session.Send(pdfBytes, 0, pdfBytes.Length) Console.WriteLine("PDF document sent to client.") End If End Sub If Not appServer.Start() Then Console.WriteLine("Failed to start!") Return End If Console.WriteLine("Server is running. Press any key to stop...") Console.ReadKey() appServer.Stop() End Sub Private Shared Function CreatePdfDocument(ByVal content As String) As PdfDocument Dim pdfRenderer = New ChromePdfRenderer() Dim pdfDocument = pdfRenderer.RenderHtmlAsPdf(content) Return pdfDocument End Function Private Shared Sub NewSessionConnected(ByVal session As AppSession) Console.WriteLine($"New session connected: {session.SessionID}") End Sub End Class Public Class AppServer Inherits AppServer(Of AppSession, StringRequestInfo) End Class Public Class AppSession Inherits AppSession(Of AppSession, StringRequestInfo) End Class End Namespace $vbLabelText $csharpLabel この統合により、SuperSocketサーバー内でIronPDFの強力な機能を活用し、動的なPDF生成と効率的なクライアント-サーバー間の通信を可能にします。 結論 SuperSocketにIronPDFの包括的な機能を統合することは、PDFの生成と処理をシームレスに行う、動的で高性能なサーバーアプリケーションを作成するための強力な組み合わせです。 SuperSocketの堅牢なソケットサーバーフレームワークとIronPDFの包括的なPDF機能により、データ収集システムからゲームサーバー、産業用制御システムまでのさまざまなニーズを満たすスケーラブルで多用途なアプリケーションを開発できます。 IronPDFは無料トライアルを提供しており、ライセンスは$799から始まり、開発プロジェクトに優れた価値を提供するその広範な機能を活用できます。 これら2つのライブラリを統合することで、サーバーが効率的に複雑なタスクを処理できるように簡素化し、機能性と性能を向上させることができます。 よくある質問 SuperSocket C#は何に使われますか? SuperSocket C#はサーバー側ソケットアプリケーションの開発に使用されます。これは非常に拡張性が高く、GPSサーバーや産業用制御システムといった環境で適したさまざまなネットワークプロトコルをサポートしています。 どのようにして.NETアプリケーションでHTMLをPDFに変換できますか? .NETアプリケーション内でHTML文字列をPDFに変換するにはIronPDFのRenderHtmlAsPdfメソッドを、HTMLファイルをPDFに変換するにはRenderHtmlFileAsPdfメソッドを使用できます。 .NETプロジェクトでSuperSocketサーバーを設定するにはどうすればよいですか? .NETプロジェクトでSuperSocketサーバーを設定するには、SuperSocket NuGetパッケージをインストールし、appsettings.jsonファイルでサーバーを構成し、アプリケーションコード内でサーバーを初期化する必要があります。 IronPDFはサーバー側アプリケーションをどのように強化できますか? IronPDFは動的なPDF生成と処理機能を提供することでサーバー側アプリケーションを強化し、クライアントの要求に基づくPDFドキュメントのリアルタイム生成と配信を可能にします。 SuperSocketは複数のプロトコルリスナーを管理できますか? はい、SuperSocketは複数のプロトコルリスナーを管理することができ、単一のサーバーインスタンスで多数のプロトコルとポートを同時に処理できます。 IronPDFはPDFドキュメントの処理に対してどのような利点を提供しますか? IronPDFはPDFドキュメントの作成、編集、およびコンテンツの抽出に対する包括的な機能を提供します。これは、高度なPDF処理と操作が必要なアプリケーションに理想的です。 SuperSocketはどのようにして同時ソケット接続を処理しますか? SuperSocketはセッションクラスを使用して接続イベントを管理し、高負荷の下でも信頼できる通信と堅牢なサーバーパフォーマンスを保証します。 SuperSocketアプリケーションにPDF機能を統合することは可能ですか? はい、SuperSocketアプリケーションにIronPDFを統合することで、動的なPDF生成と編集などのPDF機能を追加してアプリケーションの能力を向上させることができます。 SuperSocketの一般的な使用例は何ですか? SuperSocketの一般的な使用例には、GPSサーバー、産業用制御システム、データ収集サーバー、リアルタイムゲームサーバーなどがあります。これらはすべて効率的で信頼性のあるソケット通信の恩恵を受けます。 SuperSocketでバイナリデータをどのように処理できますか? SuperSocketはセッションクラスを利用してバイナリデータを効率的に処理し、受信したバイナリパッケージを処理してレスポンスを送信します。これはバイナリレベルのデータ処理が必要なアプリケーションに不可欠です。 IronPDFはサーバーアプリケーションでHTMLからPDFへの変換をサポートしていますか? はい、IronPDFはサーバーアプリケーションでのHTMLからPDFへの変換をサポートしており、HTMLコンテンツをシームレスに高品質のPDFドキュメントに変換できます。 Curtis Chau 今すぐエンジニアリングチームとチャット テクニカルライター Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。 関連する記事 更新日 9月 4, 2025 RandomNumberGenerator C# RandomNumberGenerator C#クラスを使用すると、PDF生成および編集プロジェクトを次のレベルに引き上げることができます 詳しく読む 更新日 9月 4, 2025 C# String Equals(開発者向けの仕組み) 強力なPDFライブラリであるIronPDFと組み合わせることで、switchパターンマッチングは、ドキュメント処理のためのよりスマートでクリーンなロジックを構築できます 詳しく読む 更新日 8月 5, 2025 C# Switch Pattern Matching(開発者向けの仕組み) 強力なPDFライブラリであるIronPDFと組み合わせることで、switchパターンマッチングは、ドキュメント処理のためのよりスマートでクリーンなロジックを構築できます 詳しく読む Quartz .NET(開発者向けの動作方法)Dottrace .NET Core(開発者向...
更新日 9月 4, 2025 RandomNumberGenerator C# RandomNumberGenerator C#クラスを使用すると、PDF生成および編集プロジェクトを次のレベルに引き上げることができます 詳しく読む
更新日 9月 4, 2025 C# String Equals(開発者向けの仕組み) 強力なPDFライブラリであるIronPDFと組み合わせることで、switchパターンマッチングは、ドキュメント処理のためのよりスマートでクリーンなロジックを構築できます 詳しく読む
更新日 8月 5, 2025 C# Switch Pattern Matching(開発者向けの仕組み) 強力なPDFライブラリであるIronPDFと組み合わせることで、switchパターンマッチングは、ドキュメント処理のためのよりスマートでクリーンなロジックを構築できます 詳しく読む