Altbilgi içeriğine atla
.NET YARDıM

Supersocket C# Örneği (Geliştiriciler İçin Nasıl Çalışır)

SuperSocket ile Sunucu Taraflı Bir Socket Uygulaması Geliştirme ve IronPDF Entegrasyonu

SuperSocket C# bir GPS sunucusu veya endüstriyel kontrol sistemi üzerinde çalışan bir sunucu taraflı socket uygulaması geliştirmek için harika bir çerçevedir. Çok çeşitli ağ protokol uygulamalarını destekler ve soketinizin verimli çalışmasını sağlar. Bu hafif, platformlar arası çerçeve, farklı ortamlara esneklik sağlayan şekilde genişletilebilir olarak tasarlanmıştır. SuperSocket ile istemciler ve sunucular arasında kolayca veri gönderebilirsiniz. Kaynak kodu, özellikle belirli proje gereksinimlerine uyacak şekilde özelleştirme için kullanılabilir.

Açık kaynaklı bir çerçevedir, bu yüzden her geliştirici bunu uygulayabilir ve GitHub üzerinden erişebilir.

SuperSocket C# Örneği (Geliştiriciler için Nasıl Çalışır): Şekil 1 - SuperSocket için GitHub sayfası

IronPDF, PDF belgelerini oluşturma, düzenleme ve içeriğini çıkarma için güçlü bir .NET kütüphanesidir. Uygulamalarına PDF işlevlerini entegre etmesi gereken geliştiriciler için tasarlanmıştır. IronPDF, HTML'den PDF oluşturma, PDF birleştirme ve PDF'lerden metin ve görüntü çıkarma gibi çeşitli özellikleri destekler.

SuperSocket ve IronPDF birlikte karmaşık sunucu taraflı uygulamaları güçlendirebilir. Modern .NET geliştiricilerinin ihtiyaçlarını karşılamak için geniş bir fonksiyon yelpazesi sunarlar. Bu kütüphaneler, bir veri toplama sunucusu ya da gerçek zamanlı sohbet uygulamalarının gerekli olduğu sağlam bir oyun sunucusu inşa ediyor olsanız da mükemmeldir.

SuperSocket C# ile Başlarken

.NET Projelerinde SuperSocket C# Kurulumu

SuperSocket C#'ı kullanmaya başlamak için, .NET projenizi kurmanız gerekir. İlk olarak, SuperSocket NuGet paketini kurun. Projenizi Visual Studio'da açın ve Paket Yöneticisi Konsolu'nda aşağıdaki komutu çalıştırın:

Install-Package SuperSocket

SuperSocket C# Örneği (Geliştiriciler için Nasıl Çalışır): Şekil 2 - SuperSocket kurulumundan konsol çıktısı

Kurulduktan sonra, sunucu instansınızı yapılandırabilirsiniz. Yeni bir yapılandırma dosyası oluşturun ve adını appsettings.json koyun. Bu dosya, dinleyiciler ve protokoller de dahil olmak üzere sunucu ayarlarını tanımlayacaktır.

{
  "serverOptions": {
    "name": "SuperSocketServer",
    "listeners": [
      {
        "ip": "Any",
        "port": 4040
      }
    ]
  }
}

Ardından, sunucuyu yapılandıracak bir sınıf oluşturun. Bu sınıf, ayarları appsettings.json dosyasından okuyacak ve sunucu örneğini başlatacaktır.

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

Temel SuperSocket C# Ornegi

SuperSocket C# uygulamasının temel bir örneğine bakalım. Bu örnek, alınan verileri geri gönderen basit bir yankı sunucunun nasıl oluşturulacağını göstermektedir.

İlk olarak, oturum sınıfını tanımlayın. Bu sınıf, soket bağlantılarını yönetir ve veri iletişimini sağlar.

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

Sonra, yankı oturumu ile sunucuyu yapılandırın ve çalıştırın.

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

Bu örnek, SuperSocket C# kullanarak basit bir yankı sunucunun nasıl oluşturulacağını göstermektedir. Sunucu, bağlantıları dinler ve aldığı verileri geri gönderir.

SuperSocket C# Özelliklerini Uygulama

Birden Çok Dinleyiciyi Yönetme

SuperSocket C#, sunucunun farklı protokolleri ve portları yönetmesine izin vererek birden fazla dinleyiciyi destekler. Bu özellik, veri toplama sunucuları ve GPS sunucuları gibi çeşitli uygulamaların oluşturulması için kullanışlıdır.

Önce, appsettings.json dosyanızı güncelleyerek birden fazla dinleyici ekleyin:

{
  "serverOptions": {
    "name": "MultiListenerServer",
    "listeners": [
      {
        "ip": "Any",
        "port": 4040
      },
      {
        "ip": "Any",
        "port": 5050
      }
    ]
  }
}

Sonra, bu dinleyicileri kullanacak şekilde sunucuyu yapılandırın:

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

Bu kurulumla, sunucunuz hem 4040 hem de 5050 portlarında bağlantıları yönetebilir. Bu yetenek, çeşitli ağ protokollerini yönetmesi gereken uygulamalar için hayati önem taşır.

İkili Veri İşleme Uygulaması

SuperSocket C#, ikili verileri yönetmede etkilidir. Bu, endüstriyel kontrol sistemleri gibi ikili düzeyde uyumluluk gerektiren uygulamalar için önemlidir.

İlk olarak, ikili verileri işleyen bir oturum sınıfı tanımlayın:

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

Sonra, ikili veri oturumu ile sunucuyu yapılandırın ve çalıştırın:

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

Bu örnek, SuperSocket C# kullanarak ikili verileri almanın ve göndermenin nasıl yapılacağını göstermektedir. İkili protokolleri işlemeyi gerektiren yüksek performanslı uygulamalar için kullanışlıdır.

Soket Bağlantılarını Yönetme

Soket bağlantılarını sürdürmek, güvenilir iletişim sağlamak için esastır. SuperSocket C#, bu süreci basitleştirir.

İlk olarak, soket bağlantılarını yöneten bir oturum sınıfı tanımlayın:

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

Sonra, bağlantı oturumu ile sunucuyu yapılandırın ve çalıştırın:

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

Bu kurulum, sunucunuzun sağlam ve güvenilir kalmasını sağlayarak soket bağlantılarını yönetmeye yardımcı olur.

Komut Satırı Sunucusu Oluşturma

SuperSocket C#, komut satırı sunucuları oluşturmayı destekler. Bu özellik, basit metin tabanlı protokoller gerektiren uygulamalar için kullanışlıdır.

İlk olarak, metin komutlarını işleyen bir komut sınıfı tanımlayın:

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

Sonra, sunucuyu komutu kullanacak şekilde yapılandırın:

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

Bu örnek, SuperSocket C# kullanarak basit bir komut satırı sunucunun nasıl oluşturulacağını göstermektedir. Hafif metin tabanlı protokoller için idealdir.

SuperSocket C# ile IronPDF Entegrasyonu

IronPDF'i SuperSocket ile C# uygulamalarınızda entegre etmek, özellikle PDF dosyalarını yönetme konusunda sunucu kapasitenizi önemli ölçüde artırabilir. Bu iki güçlü kütüphaneyi etkili bir şekilde nasıl birleştireceğimizi keşfedelim.

IronPDF'ye Giriş

IronPDF web sayfası

IronPDF .NET Kütüphanesi, PDF belgelerini oluşturmak, düzenlemek ve içeriğini çıkarmak için tasarlanmış çok yönlü bir .NET kütüphanesidir. İster raporlar, ister faturalar ya da başka herhangi bir PDF tabanlı belge üretmeniz gereken durumlarda, IronPDF, bu görevleri gerçekleştirmek için kolay kullanımlı bir API sunar. Ana özelliği, HTML'den PDFe Dönüştürme yetenekleridir. PDF işlevselliğini uygulamalarına entegre etmek isteyen geliştiriciler için, PDF belgeleriyle uğraşmanın zorluklarıyla karşılaşmadan mükemmel bir araçtır.

HTML'den PDF'ye dönüştürmede IronPDF, özgün düzenlerin ve tarzların hassas korunmasını sağlamakta üstünlük sağlar. Web tabanlı içeriklerden, örneğin raporlar, faturalar ve belgeler gibi PDF'ler oluşturmak için mükemmeldir. HTML dosyaları, URL'ler ve ham HTML dizeleri desteği ile IronPDF kolaylıkla yüksek kaliteli PDF belgeler üretir.

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'yi SuperSocket C# ile Birleştirme Kullanım Senaryosu

SuperSocket kullanılarak oluşturulmuş ve istemci taleplerini dinamik olarak PDF belgeleri oluşturup göndermesi gereken bir sunucuya sahip olduğunuzu hayal edin. IronPDF'i entegre ederek, sunucunuz bu istekleri işleyebilir, uçuşta PDF'ler oluşturabilir ve onları sorunsuz bir şekilde istemcilere geri gönderebilir.

Kullanım Senaryosu Kod Örneği

IronPDF'i SuperSocket ile entegre etmenin nasıl yapılacağını gösteren tam bir kod örneği burada. Bu örnek, istemci bağlantılarını dinleyen, bir PDF oluşturma isteğini işleyen ve oluşturulan PDF'yi istemciye geri gönderen basit bir SuperSocket sunucusunu kurar.

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

Bu entegrasyon, IronPDF'in güçlü özelliklerinden SuperSocket sunucu içerisinde yararlanarak dinamik PDF oluşturma ve etkin istemci-sunucu iletişimi sağlar.

Sonuç

IronPDF lisanslama bilgileri

IronPDF'in Kapsamlı Özellikleri ile SuperSocket entegrasyon, PDF oluşturma ve işleme işlemlerini sorunsuz bir şekilde yönetebilecek dinamik, yüksek performanslı sunucu uygulamaları oluşturmak için güçlü bir kombinasyon sunar. SuperSocket'in sağlam soket sunucu çerçevesi ve IronPDF'in kapsamlı PDF işlevsellikleri ile, çeşitli ihtiyaçları karşılayan, veri toplama sistemlerinden oyun sunucularına ve endüstriyel kontrol sistemlerine kadar genişletilebilir ve çok yönlü uygulamalar geliştirebilirsiniz.

IronPDF, ücretsiz bir deneme sunar ve lisanslaması $799 ile başlar, bu da geliştirme projelerinize getirdiği geniş kapsamlı yetenekler için harika bir değer sağlar. Bu iki kütüphaneyi birleştirerek, sunucunuzun karmaşık görevleri etkin bir şekilde yönetebilme kapasitesini artırabilirsiniz, bu da hem işlevselliği hem de performansı geliştirir.

Sıkça Sorulan Sorular

SuperSocket C# ne için kullanilir?

SuperSocket C#, sunucu tarafinda soket uygulamalari geliştirmek için kullanilir. Son derece genişletilebilir ve çeşitli ağ protokollerini destekler, bu da onu GPS sunucuları ve endustriyel kontrol sistemleri gibi ortamlara uygun hale getirir.

Bir .NET uygulamasinda HTML'yi PDF'ye nasıl dönüştürebilirim?

IronPDF'in RenderHtmlAsPdf metodunu HTML dizgilerini PDF'lere ve RenderHtmlFileAsPdf'i HTML dosyalarını PDF'lere dönüştürmek için .NET uygulamasında kullanabilirsiniz.

.NET projesinde bir SuperSocket sunucusu nasıl kurulur?

.NET projesinde bir SuperSocket sunucusu kurmak için, SuperSocket NuGet paketini kurmanız, appsettings.json dosyasını kullanarak sunucuyu konfigüre etmeniz ve uygulama kodunuzda sunucuyu başlatmaniz gerekir.

IronPDF, sunucu-tarafı uygulamaları nasıl geliştirebilir?

IronPDF, dinamik PDF oluşturma ve işleme yetenekleri sunarak sunucu-tarafı uygulamalarını geliştirir ve müşteri taleplerine dayalı olarak PDF belgelerinin gerçek zamanlı oluşturulması ve dağıtılmasını sağlar.

SuperSocket, birden fazla protokol dinleyicisini yönetebilir mi?

Evet, SuperSocket, birden fazla protokol dinleyicisini yönetebilir, bu da tek bir sunucu örneğinin veri toplama sunucuları gibi çeşitli protokolleri ve portları aynı anda ele almasını sağlar.

IronPDF, PDF belge işlemleri için ne gibi faydalar sunar?

IronPDF, PDF belgelerini oluşturmak, düzenlemek ve içerik çıkarmak için kapsamlı özellikler sunar. Gelişmiş PDF belge işlemleri ve manipülasyonu gerektiren uygulamalar için idealdir.

SuperSocket, eşzamanlı soket bağlantılarını nasıl yönetir?

SuperSocket, eşzamanlı soket bağlantılarını yönetmek için bağlantı olaylarını yönetmek üzere oturum sınıflarını kullanarak, yüksek yük altında bile güvenilir iletişim ve sağlam sunucu performansını sağlar.

SuperSocket uygulamalarina PDF işlevleri eklemek mumkun mudur?

Evet, SuperSocket uygulamalarınıza IronPDF'i entegre ederek, dinamik PDF oluşturma ve düzenleme gibi PDF işlevleri ekleyebilir ve uygulamanın yeteneklerini genişletebilirsiniz.

SuperSocket için yaygin kullanım durumlari nelerdir?

SuperSocket için yaygın kullanım durumları, verimli ve güvenilir soket iletişimini sunmak için GPS sunucuları, endüstriyel kontrol sistemleri, veri toplama sunucuları ve gerçek zamanlı oyun sunucuları gibi alanları içerir.

SuperSocket'te ikili verileri nasıl ele alabilirim?

SuperSocket, gelen ikili paketleri işlemek ve yanıtlar göndermek için oturum sınıflarını kullanarak, ikili düzeyde veri işlemeye ihtiyaç duyan uygulamalar için ikili verileri verimli bir şekilde ele alır.

IronPDF, sunucuda uygulamalarda HTML'den PDF'e dönüştürmeyi destekliyor mu?

Evet, IronPDF, HTML içeriğini sorunsuz bir şekilde yüksek kaliteli PDF belgelere dönüştürmek için sunucu uygulamalarında HTML'den PDF'e dönüşümü destekler.

Jacob Mellor, Teknoloji Direktörü @ Team Iron
Chief Technology Officer

Jacob Mellor, Iron Software'in Teknoloji Müdürü ve C# PDF teknolojisinin öncüsü olan vizyoner bir mühendis. Iron Software’in temel kod tabanının ilk geliştiricisi olarak, şirketin ürün mimarisini kuruluşundan bu yana şekillendirdi ve CEO Cameron Rimington ile birlikte NASA, Tesla ve ...

Daha Fazlasını Oku

Iron Destek Ekibi

Haftanın 5 günü, 24 saat çevrimiçiyiz.
Sohbet
E-posta
Beni Ara