LEADTOOLS JPEG 2000 (Leadtools.Jpip assembly)
LEAD Technologies, Inc

HttpRequestEncoder Class

Example 





Members 
Converts a client Leadtools.Jpip.RequestFields and parameters into an System.Net.HttpWebRequest object.
Object Model
HttpRequestEncoder Class
Syntax
public class HttpRequestEncoder 
'Declaration
 
Public Class HttpRequestEncoder 
'Usage
 
Dim instance As HttpRequestEncoder
public sealed class HttpRequestEncoder 
function Leadtools.Jpip.RequestEncoder.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
 
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
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: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

HttpRequestEncoder Members
Leadtools.Jpip.RequestEncoder Namespace

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 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