LEADTOOLS JPEG 2000 (Leadtools.Jpip assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
HttpRequestEncoder Class
See Also  Members  
Leadtools.Jpip.RequestEncoder Namespace : HttpRequestEncoder Class



The HttpRequestEncoder Class includes members that are available as an add-on to the LEADTOOLS Imaging Pro, Document, and Medical Imaging toolkits.

Converts a client Leadtools.Jpip.RequestFields and parameters into an System.Net.HttpWebRequest object.

Object Model

HttpRequestEncoder Class

Syntax

Visual Basic (Declaration) 
Public Class HttpRequestEncoder 
Visual Basic (Usage)Copy Code
Dim instance As HttpRequestEncoder
C# 
public class HttpRequestEncoder 
C++/CLI 
public ref class HttpRequestEncoder 

Example

Visual BasicCopy Code
Public Class HttpClientCommunication
   Private Sub SendClientRequest()
      Dim fields As RequestFields = New RequestFields()
      Dim cacheModleItem As ModelItem
      Dim binDescriptor As ExplicitBinDescriptor
      Dim cacheModleElement As ModelElement

      fields.RequestTargetFields = New TargetFields("0", "image1.jp2", Nothing)

      fields.RequestChannelFields.NewChannel = New String() {"http"}

      fields.RequestDataLimitFields.DataLength = 16384

      cacheModleItem = New ModelItem()
      binDescriptor = New ExplicitBinDescriptor(ExplicitBin.MetaBin, 0, Nothing) 'indicate that metadata bin 0 is locally cached and need not be sent.
      cacheModleElement = New ModelElement(False, binDescriptor)

      cacheModleItem.BinDescriptors.Add(cacheModleElement)
      cacheModleItem.CodeStreamRange.Add(New Range(0, 0))

      fields.RequestCacheManagementFields.ModelItems.Add(cacheModleItem)

      Dim imageType As ImageReturnType = New ImageReturnType(ImageTypes.JppStream, False)

      fields.RequestServerControlFields.ImageReturnTypes = New ImageReturnType() {imageType}

      fields.RequestViewWindowFields.FrameSize = New LeadSize(500, 300)
      fields.RequestViewWindowFields.RegionOffset = New LeadPoint(0, 100)
      fields.RequestViewWindowFields.FrameSizeRoundingDirection = RoundingDirection.Closest

      Dim codeStreamRange As SampleRange = New SampleRange()

      codeStreamRange.Range = New Range(0, 0)

      fields.RequestViewWindowFields.CodeStream.Add(codeStreamRange)

      Dim encoder As HttpRequestEncoder = New HttpRequestEncoder(IPAddress.Parse("127.0.0.1"), 108)

      Dim request As HttpWebRequest = encoder.Encode(fields, "jpip", Nothing)

      Console.WriteLine(request.Address.ToString())

      Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)

      Console.WriteLine("Server response received.")

      Console.WriteLine(response.Headers.ToString())
   End Sub

   Private Function GetClientSocket() As Socket

      Dim listenSocket As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

      Dim hostIP As IPAddress = IPAddress.Parse("127.0.0.1")
      Dim port As Integer = 107

      Dim ep As IPEndPoint = New IPEndPoint(hostIP, port)

      listenSocket.Bind(ep)

      ' start listening
      listenSocket.Listen(10)

      'a client should send a request to the listening address
      Dim client As Socket = listenSocket.Accept()

      listenSocket.Close()

      Return client
   End Function
End Class
C#Copy Code
public void SendClientRequest()
{
    Leadtools.Examples.Support.Unlock();
   RequestFields fields = new RequestFields();
   ModelItem cacheModleItem;
   ExplicitBinDescriptor binDescriptor;
   ModelElement cacheModleElement;
   fields.RequestTargetFields = new TargetFields("0", "image1.jp2", null);
   fields.RequestChannelFields.NewChannel = new string[] { "http" };
   fields.RequestDataLimitFields.DataLength = 16384;
   cacheModleItem = new ModelItem();
   binDescriptor = new ExplicitBinDescriptor(ExplicitBin.MetaBin, 0, null); //indicate that metadata bin 0 is locally cached and need not be sent.
   cacheModleElement = new ModelElement(false, binDescriptor);
   cacheModleItem.BinDescriptors.Add(cacheModleElement);
   cacheModleItem.CodeStreamRange.Add(new Range(0, 0));
   fields.RequestCacheManagementFields.ModelItems.Add(cacheModleItem);
   ImageReturnType imageType = new ImageReturnType(ImageTypes.JppStream, false);
   fields.RequestServerControlFields.ImageReturnTypes = new ImageReturnType[] { imageType };
   fields.RequestViewWindowFields.FrameSize = new LeadSize(500, 300);
   fields.RequestViewWindowFields.RegionOffset = new LeadPoint(0, 100);
   fields.RequestViewWindowFields.FrameSizeRoundingDirection = RoundingDirection.Closest;
   SampleRange codeStreamRange = new SampleRange();
   codeStreamRange.Range = new Range(0, 0);
   fields.RequestViewWindowFields.CodeStream.Add(codeStreamRange);
   HttpRequestEncoder encoder = new HttpRequestEncoder(IPAddress.Parse("127.0.0.1"), 108);
   HttpWebRequest request = encoder.Encode(fields, "jpip", null);
   Console.WriteLine(request.Address.ToString());
   HttpWebResponse response = (HttpWebResponse) request.GetResponse();
   Console.WriteLine("Server response received.");
   Console.WriteLine(response.Headers.ToString());
}

public Socket GetClientSocket()
{
   Socket listenSocket = new Socket( AddressFamily.InterNetwork,
                                     SocketType.Stream,
                                     ProtocolType.Tcp);
   IPAddress hostIP = IPAddress.Parse("127.0.0.1");
   int port = 107;
   IPEndPoint ep = new IPEndPoint(hostIP, port);
   listenSocket.Bind(ep);
   // start listening
   listenSocket.Listen(10);
   //a client should send a request to the listening address
   Socket client = listenSocket.Accept();
   listenSocket.Close();
   return client;
}

Remarks

Use this class to create an System.Net.HttpWebRequest which holds the JPIP parameters to be sent to the server.

Inheritance Hierarchy

System.Object
   Leadtools.Jpip.RequestEncoder.HttpRequestEncoder

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7

See Also

Leadtools.Jpip requires a JPIP Module and a server license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features