Leadtools.Jpip Requires JPIP module product license | Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
HttpRequestEncoder Class
See Also  Members   Example 
Leadtools.Jpip.RequestEncoder Namespace : HttpRequestEncoder Class



Converts a client RequestFields and parameters into an HttpWebRequest object.

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
   <Test> _
   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 Size(500, 300)
      fields.RequestViewWindowFields.FrameSizeRoundingDirection = RoundingDirection.Closest
      fields.RequestViewWindowFields.RegionOffset = New Point(0, 100)

      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 Size(500, 300); 
   fields.RequestViewWindowFields.FrameSizeRoundingDirection = RoundingDirection.Closest; 
   fields.RequestViewWindowFields.RegionOffset = new Point(0, 100); 
   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 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 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

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