LEADTOOLS JPEG 2000 (Leadtools.Jpip assembly)

HttpRequestEncoder Class

Show in webframe
Example 





Members 
Converts a client Leadtools.Jpip.RequestFields and parameters into an System.Net.HttpWebRequest object.
Object Model
Syntax
public class HttpRequestEncoder 
'Declaration
 
Public Class HttpRequestEncoder 
'Usage
 
Dim instance As HttpRequestEncoder

            

            
public ref class HttpRequestEncoder 
Remarks

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

Example
Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Jpip
Imports Leadtools.Jpip.Caching
Imports Leadtools.Jpip.HttpServer
Imports Leadtools.Jpip.RequestDecoder
Imports Leadtools.Jpip.RequestEncoder
Imports Leadtools.Jpip.Client.WinForms
Imports Leadtools.Jpip.Client.InteractiveDecoder
Imports Leadtools.Jpip.Server
Imports Leadtools.Jpip.Logging

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
using Leadtools;
         using Leadtools.Codecs;
         using Leadtools.Jpip;
         using Leadtools.Jpip.Caching ;
         using Leadtools.Jpip.HttpServer;
         using Leadtools.Jpip.RequestDecoder;
         using Leadtools.Jpip.RequestEncoder;
         using Leadtools.Jpip.Client.WinForms;
         using Leadtools.Jpip.Client.InteractiveDecoder;
         using Leadtools.Jpip.Server;
         using Leadtools.Jpip.Logging;

         public void SendClientRequest()
         {
#if LEADTOOLS_V175_OR_LATER
            Leadtools.Examples.Support.SetLicense();
#else
            Leadtools.Examples.Support.Unlock();
#endif // #if LEADTOOLS_V175_OR_LATER
            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;
         }
Requirements

Target Platforms

See Also

Reference

HttpRequestEncoder Members
Leadtools.Jpip.RequestEncoder Namespace

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.

Leadtools.Jpip requires a JPIP Module and a server license and unlock key. For more information, refer to: LEADTOOLS Toolkit Features