public class JpipServer Public Class JpipServer
public ref class JpipServer Using the JpipServer class, you can create a JPIP protocol server that responds to JPIP requests from any JPIP-compliant client.
To start the server, create a JpipServer object then set the Configuration values and call the Start method, the JpipServer will listen to requests in a background threads causing the application main thread not to block.
When you are done with the JpipServer object call the Stop method.
using Leadtools;using Leadtools.Codecs;using Leadtools.Jpip;using Leadtools.Jpip.Client.WinForms;using Leadtools.Jpip.Client.InteractiveDecoder;using Leadtools.Jpip.Server;using Leadtools.Jpip.Logging;private JpipServer _server;private WindowsLogWriter _logWriter;private int _responseCount;private string _loggingFileName;private bool _loggingFileEnabled;private const string LOCAL_IP_ADDRESS = "127.0.0.1";private const string SERVER_NAME = "LEAD JPIP Server - Test Server";private const int PORT_107 = 107;private string CACHE_DIRECTORY = Path.Combine(LEAD_VARS.ImagesDir, "jpeg2000");private string IMAGES_DIRECTORY = Path.Combine(LEAD_VARS.ImagesDir, "jpeg2000");private string IMAGE_NAME = Path.Combine(LEAD_VARS.ImagesDir, "Earth8000_Precint_4_.j2k");private string LOG_DIRECTORY = Path.Combine(LEAD_VARS.ImagesDir, "Server Logs");private string LOG_FILE_NAME = Path.Combine(LEAD_VARS.ImagesDir, "log.txt");public RunServerExamples(){Leadtools.Examples.Support.SetLicense();_server = new JpipServer();_logWriter = new WindowsLogWriter();_responseCount = 0;_loggingFileEnabled = true;if (!File.Exists(LOG_DIRECTORY + LOG_FILE_NAME)){Directory.CreateDirectory(LOG_DIRECTORY);File.WriteAllText(LOG_FILE_NAME, " ");}_loggingFileName = LOG_FILE_NAME;}void EventLogger_EventLog(object sender, Leadtools.Jpip.Logging.EventLogEntry e){Console.WriteLine("Server Name: {0}; Server IP: {1}; Server Port: {2}; Client IP: {3}; Client Port: {4}; Channel ID: {5}; Event Type: {6}; Description: {7}",e.ServerName, e.ServerIPAddress, e.ServerPort,e.ClientIPAddress, e.ClientPort, e.ChannelID,e.Type.ToString(), e.Description);}void _server_ResponseSending(object sender, ResponseSendingEventArgs e){string dataFolder;string dumpClientIP;int dumpClientPort;dataFolder = Path.Combine(LEAD_VARS.ImagesDir, "ServerResponses");dumpClientIP = "127.0.0.1";dumpClientPort = 1207;if (!Directory.Exists(dataFolder)){Directory.CreateDirectory(dataFolder);}if ((e.ClientIpAddress == dumpClientIP) && (e.ClientPort == dumpClientPort)){string subDirectoryPath;string responseDataFile;_responseCount++;subDirectoryPath = string.Concat(dataFolder, "\\", dumpClientIP);responseDataFile = string.Concat(subDirectoryPath, "\\response_", _responseCount);if (!Directory.Exists(subDirectoryPath)){Directory.CreateDirectory(subDirectoryPath);}File.WriteAllBytes(responseDataFile, e.Data);}}void _server_RequestReceived(object sender, RequestReceivedEventArgs e){string denyClientIpAddress = "127.0.0.1";int denyClientPort = 120;if ((e.ClientIpAddress == denyClientIpAddress) && (e.ClientPort == denyClientPort)){e.Deny = true;e.StatusCode = (int)HttpStatusCode.Forbidden;e.Description = "Server refused to process request.";}}public void ResetServerConfiguration(){if (!_server.IsRunning){JpipConfiguration appConfigSettings;//for reading from configuration file settingsappConfigSettings = new JpipConfiguration();//Server Settings_server.Configuration.ServerName = SERVER_NAME;_server.Configuration.IPAddress = LOCAL_IP_ADDRESS;_server.Configuration.Port = PORT_107;_server.Configuration.ImagesFolder = IMAGES_DIRECTORY;_server.Configuration.CacheFolder = CACHE_DIRECTORY;_server.Configuration.MaxServerBandwidth = ConfigurationDefaults.MaxServerBandwidth;_server.Configuration.CacheSize = appConfigSettings.CacheSize;_server.Configuration.DivideSuperBoxes = true;_server.Configuration.ChunkSize = 512;_server.Configuration.MaxClientCount = 5;_server.Configuration.ConnectionIdleTimeout = TimeSpan.FromSeconds(ConfigurationDefaults.ConnectionIdleTimeout);_server.Configuration.MaxSessionLifetime = TimeSpan.FromSeconds(ConfigurationDefaults.MaxSessionLifetime);_server.Configuration.MaxConnectionBandwidth = ConfigurationDefaults.MaxConnectionBandwidth;//Communication Settings_server.Configuration.MaxTransportConnections = 15;_server.Configuration.HandshakeTimeout = TimeSpan.FromSeconds(ConfigurationDefaults.HandshakeTimeout);_server.Configuration.RequestTimeout = TimeSpan.FromSeconds(ConfigurationDefaults.RequestTimeout);_server.Configuration.ChunkSize = ConfigurationDefaults.ChunkSize;//Images Settings_server.Configuration.ImageParsingTimeout = TimeSpan.FromSeconds(ConfigurationDefaults.ImageParsingTimeout);_server.Configuration.PartitionBoxSize = 30;_server.Configuration.DivideSuperBoxes = appConfigSettings.DivideSuperBoxes;//Logging Settings_server.Configuration.LoggingFile = _loggingFileName;_server.Configuration.EnableLogging = _loggingFileEnabled;_server.Configuration.LogInformation = true;_server.Configuration.LogWarnings = true;_server.Configuration.LogDebug = true;_server.Configuration.LogErrors = true;AddAliasFolders();}}private void AddAliasFolders(){string alias = "LeadImages";string physicalPath = LEAD_VARS.ImagesDir;//Set server aliases folderif (_server.Configuration.IsAliasExists(alias)){if (_server.Configuration.GetAliasPath(alias) != physicalPath){_server.Configuration.RemoveAliasFolder(alias);}else{return;}}_server.Configuration.AddAliasFolder(alias, physicalPath);}public void SetViewer(JpipRasterImageViewer viewer){viewer.CacheDirectoryName = CACHE_DIRECTORY;viewer.PortNumber = PORT_107;viewer.IPAddress = LOCAL_IP_ADDRESS;viewer.PacketSize = 16384;viewer.ChannelType = JpipChannelTypes.HttpChannel;}private class WindowsLogWriter : ILoggingChannel{public void WriteLog(Leadtools.Jpip.Logging.EventLogEntry logEntry){string message;message = string.Format("Server Name: {0}; Server IP: {1}; Server Port: {2}; Client IP: {3}; Client Port: {4}; Channel ID: {5}; Event Type: {6}; Description: {7}",logEntry.ServerName, logEntry.ServerIPAddress, logEntry.ServerPort,logEntry.ClientIPAddress, logEntry.ClientPort, logEntry.ChannelID,logEntry.Type.ToString(), logEntry.Description);System.Diagnostics.EventLog.WriteEntry("JPIP LEAD Server", message);}}public void StartServer(){ResetServerConfiguration();//Interactive handling_server.RequestReceived += new EventHandler<RequestReceivedEventArgs>(_server_RequestReceived);_server.ResponseSending += new EventHandler<ResponseSendingEventArgs>(_server_ResponseSending);//Handle event logsEventLogger.EventLog += new EventHandler<Leadtools.Jpip.Logging.EventLogEntry>(EventLogger_EventLog);//clear the server cache_server.ClearCacheContents();//Add custom logging channelif (!EventLogger.ContainsLoggingChannel(_logWriter)){EventLogger.AddLoggingChannel(_logWriter);}EventLogger.LogEvent(SERVER_NAME, LOCAL_IP_ADDRESS, PORT_107.ToString(), "", "",DateTime.Now, Leadtools.Jpip.Logging.EventLogEntryEventType.Information,"", "LEAD Example Started");//start the server_server.Start();Debug.Assert(_server.IsRunning, "Server did not start.");/* client side */JpipRasterImageViewer jpipViewer = new JpipRasterImageViewer();jpipViewer.FileOpened += new EventHandler(jpipViewer_FileOpened);SetViewer(jpipViewer);jpipViewer.Open(IMAGE_NAME);}void jpipViewer_FileOpened(object sender, EventArgs e){JpipRasterImageViewer jpipViewer = (JpipRasterImageViewer)sender;jpipViewer.ZoomIn();jpipViewer.Close();/*Server side*/if (_server.IsRunning){_server.Stop();}EventLogger.LogEvent(SERVER_NAME, LOCAL_IP_ADDRESS, PORT_107.ToString(), "", "",DateTime.Now, Leadtools.Jpip.Logging.EventLogEntryEventType.Information,"", "LEAD Example Ended");}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.JpipImports Leadtools.Jpip.Client.WinFormsImports Leadtools.Jpip.Client.InteractiveDecoderImports Leadtools.Jpip.ServerImports Leadtools.Jpip.Logging<TestClass()>Public Class RunServerExamplePrivate _server As JpipServerPrivate _logWriter As WindowsLogWriterPrivate _responseCount As IntegerPrivate _loggingFileName As StringPrivate _loggingFileEnabled As BooleanPrivate Const LOCAL_IP_ADDRESS As String = "127.0.0.1"Private Const SERVER_NAME As String = "LEAD JPIP Server - Test Server"Private Const PORT_107 As Integer = 107Private CACHE_DIRECTORY As String = Path.Combine(LEAD_VARS.ImagesDir, "jpeg2000")Private IMAGES_DIRECTORY As String = Path.Combine(LEAD_VARS.ImagesDir, "jpeg2000")Private IMAGE_NAME As String = Path.Combine(LEAD_VARS.ImagesDir, "Earth8000_Precint_4_.j2k")Public Sub New()Leadtools.Examples.Support.SetLicense()_server = New JpipServer()_logWriter = New WindowsLogWriter()_responseCount = 0_loggingFileEnabled = True_loggingFileName = Path.Combine(LEAD_VARS.ImagesDir, "Server Logs\log.txt")End SubPublic Sub StartServer()ResetServerConfiguration()'Interactive handlingAddHandler _server.RequestReceived, AddressOf _server_RequestReceivedAddHandler _server.ResponseSending, AddressOf _server_ResponseSending'Handle event logsAddHandler EventLogger.EventLog, AddressOf EventLogger_EventLog'clear the server cache_server.ClearCacheContents()'Add custom logging channelIf (Not EventLogger.ContainsLoggingChannel(_logWriter)) ThenEventLogger.AddLoggingChannel(_logWriter)End IfEventLogger.LogEvent(SERVER_NAME, LOCAL_IP_ADDRESS, PORT_107.ToString(), "", "", DateTime.Now, Leadtools.Jpip.Logging.EventLogEntryEventType.Information, "", "LEAD Example Started")'start the server_server.Start()Debug.Assert(_server.IsRunning, "Server did not start.")' client sideDim jpipViewer As JpipRasterImageViewer = New JpipRasterImageViewer()SetViewer(jpipViewer)AddHandler jpipViewer.FileOpened, AddressOf jpipViewer_FileOpenedjpipViewer.Open(IMAGE_NAME)End SubPrivate Sub jpipViewer_FileOpened(ByVal sender As Object, ByVal e As EventArgs)Dim jpipViewer As JpipRasterImageViewer = DirectCast(sender, JpipRasterImageViewer)jpipViewer.ZoomIn()jpipViewer.Close()'Server sideIf _server.IsRunning Then_server.Stop()End IfEventLogger.LogEvent(SERVER_NAME, LOCAL_IP_ADDRESS, PORT_107.ToString(), "", "", DateTime.Now, Leadtools.Jpip.Logging.EventLogEntryEventType.Information, "", "LEAD Example Ended")End SubPrivate Sub EventLogger_EventLog(ByVal sender As Object, ByVal e As Leadtools.Jpip.Logging.EventLogEntry)Console.WriteLine("Server Name: {0}; Server IP: {1}; Server Port: {2}; Client IP: {3}; Client Port: {4}; Channel ID: {5}; Event Type: {6}; Description: {7}", e.ServerName, e.ServerIPAddress, e.ServerPort, e.ClientIPAddress,e.ClientPort, e.ChannelID, e.Type.ToString(), e.Description)End SubPrivate Sub _server_ResponseSending(ByVal sender As Object, ByVal e As ResponseSendingEventArgs)Dim dataFolder As StringDim dumpClientIP As StringDim dumpClientPort As IntegerdataFolder = Path.Combine(LEAD_VARS.ImagesDir, "ServerResponses")dumpClientIP = "127.0.0.1"dumpClientPort = 121If (Not Directory.Exists(dataFolder)) ThenDirectory.CreateDirectory(dataFolder)End IfIf (e.ClientIpAddress = dumpClientIP) AndAlso (e.ClientPort = dumpClientPort) ThenDim subDirectoryPath As StringDim responseDataFile As String_responseCount += 1subDirectoryPath = String.Concat(dataFolder, "\", dumpClientIP)responseDataFile = String.Concat(subDirectoryPath, "\response_", _responseCount)If (Not Directory.Exists(subDirectoryPath)) ThenDirectory.CreateDirectory(subDirectoryPath)End IfFile.WriteAllBytes(responseDataFile, e.Data)End IfEnd SubPrivate Sub _server_RequestReceived(ByVal sender As Object, ByVal e As RequestReceivedEventArgs)Dim denyClientIpAddress As String = "127.0.0.1"Dim denyClientPort As Integer = 120If (e.ClientIpAddress = denyClientIpAddress) AndAlso (e.ClientPort = denyClientPort) Thene.Deny = Truee.StatusCode = CInt(HttpStatusCode.Forbidden)e.Description = "Server refused to process request."End IfEnd SubPublic Sub ResetServerConfiguration()If (Not _server.IsRunning) ThenDim appConfigSettings As JpipConfiguration'for reading from configuration file settingsappConfigSettings = New JpipConfiguration()'Server Settings_server.Configuration.ServerName = SERVER_NAME_server.Configuration.IPAddress = LOCAL_IP_ADDRESS_server.Configuration.Port = PORT_107_server.Configuration.ImagesFolder = IMAGES_DIRECTORY_server.Configuration.CacheFolder = CACHE_DIRECTORY_server.Configuration.MaxServerBandwidth = ConfigurationDefaults.MaxServerBandwidth_server.Configuration.CacheSize = appConfigSettings.CacheSize_server.Configuration.DivideSuperBoxes = True_server.Configuration.ChunkSize = 512_server.Configuration.MaxClientCount = 5_server.Configuration.ConnectionIdleTimeout = TimeSpan.FromSeconds(ConfigurationDefaults.ConnectionIdleTimeout)_server.Configuration.MaxSessionLifetime = TimeSpan.FromSeconds(ConfigurationDefaults.MaxSessionLifetime)_server.Configuration.MaxConnectionBandwidth = ConfigurationDefaults.MaxConnectionBandwidth'Communication Settings_server.Configuration.MaxTransportConnections = 15_server.Configuration.HandshakeTimeout = TimeSpan.FromSeconds(ConfigurationDefaults.HandshakeTimeout)_server.Configuration.RequestTimeout = TimeSpan.FromSeconds(ConfigurationDefaults.RequestTimeout)_server.Configuration.ChunkSize = ConfigurationDefaults.ChunkSize'Images Settings_server.Configuration.ImageParsingTimeout = TimeSpan.FromSeconds(ConfigurationDefaults.ImageParsingTimeout)_server.Configuration.PartitionBoxSize = 30_server.Configuration.DivideSuperBoxes = appConfigSettings.DivideSuperBoxes'Logging Settings_server.Configuration.LoggingFile = _loggingFileName_server.Configuration.EnableLogging = _loggingFileEnabled_server.Configuration.LogInformation = True_server.Configuration.LogWarnings = True_server.Configuration.LogDebug = True_server.Configuration.LogErrors = TrueAddAliasFolders()End IfEnd SubPrivate Sub AddAliasFolders()Dim alias_Renamed As String = "LeadImages"Dim physicalPath As String = LEAD_VARS.ImagesDir'Set server aliases folderIf _server.Configuration.IsAliasExists(alias_Renamed) ThenIf _server.Configuration.GetAliasPath(alias_Renamed) <> physicalPath Then_server.Configuration.RemoveAliasFolder(alias_Renamed)ElseReturnEnd IfEnd If_server.Configuration.AddAliasFolder(alias_Renamed, physicalPath)End SubPublic Sub SetViewer(ByVal viewer As JpipRasterImageViewer)viewer.CacheDirectoryName = CACHE_DIRECTORYviewer.PortNumber = PORT_107viewer.IPAddress = LOCAL_IP_ADDRESSviewer.PacketSize = 16384viewer.ChannelType = JpipChannelTypes.HttpChannelEnd SubPrivate Class WindowsLogWriter : Implements ILoggingChannelPublic Sub WriteLog(ByVal logEntry As Leadtools.Jpip.Logging.EventLogEntry) Implements ILoggingChannel.WriteLogDim message As Stringmessage = String.Format("Server Name: {0}; Server IP: {1}; Server Port: {2}; Client IP: {3}; Client Port: {4}; Channel ID: {5}; Event Type: {6}; Description: {7}", logEntry.ServerName, logEntry.ServerIPAddress,logEntry.ServerPort, logEntry.ClientIPAddress, logEntry.ClientPort, logEntry.ChannelID, logEntry.Type.ToString(), logEntry.Description)System.Diagnostics.EventLog.WriteEntry("JPIP LEAD Server", message)End SubEnd ClassEnd ClassPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\LEADTOOLS21\Resources\Images"End Class
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
