NetTalk Central

Author Topic: NetSimple Server  (Read 10173 times)

Paul Blais

  • Newbie
  • *
  • Posts: 8
    • View Profile
NetSimple Server
« on: August 15, 2011, 10:42:38 AM »
I need a NetSimple server to receive a packet that will be an XML data file that I know how to read. This connection will come through a VPN and of course the one client calling is the only client that can call over the VPN but it won't be a Clarion application that can use NET:SimpleWholeDataPacket.

The XML structure is standard but the contents are variable length but will be well under 16KB more like 2KB. When I receive the partial packet how do I know when the whole packet has been received? Unlike when I use the NET:SimpleWholeDataPacket I won't really know. Given the dedicated link it should all be there very quick but how quick is pretty quick:)

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11191
    • View Profile
Re: NetSimple Server
« Reply #1 on: August 15, 2011, 09:27:47 PM »
Hi Paul,

usually there are 2 ways to determine the length of the file;

a) the sender closes the connection - this is a good sign "there is no more". Web servers for example often do this one they've finished sending a page.

b) The file is "wrapped" in some protocol which indicates the length. For example the web uses HTTP - which is a header at the top of the reply which indicates the length of the reply.

In your case there are a couple of options;

a) put some sort of item before the raw xml to indicate the length. you could even do it at the top of the xml if you like.

b) client closes the connection (assuming you don't need to send a reply).

c) parse the xml as it comes in - if it starts with
<whatever>
then you'll know it's complete when you get
</whatever>

Cheers
Bruce


Paul Blais

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: NetSimple Server
« Reply #2 on: August 16, 2011, 02:52:59 AM »
I actually got a little lucky (it's only a moment in time). I can look for a </Message> that marks the end BUT I also will receive a 4 byte length signed integer in Big Endian format. Does this code to convert to a Clarion LONG look right:

FromBEndian           PROCEDURE  (STRING RawVal)!, LONG   

ByteArray               BYTE,DIM(4)
InputVal                STRING(4),OVER(ByteArray)
Result                  LONG

  CODE


  InputVal = RawVal

  Result =  (INT(ByteArray[1]) * 256^3 + |
                  INT(ByteArray[2]) * 256^2 + |
                  INT(ByteArray[3]) * 256     + |
                  INT(ByteArray[4])) - 4

  RETURN Result

Looking at the docs (late yesterday) this looks like a popular method for passing the length. It might be worth an option to support "big endian" format as a passed length for WholePacket

With the leading length a </Message> closing it should not be that hard.

If the server closes the connection before I give up what event will fire on my end? I know I have to probably do this a few more times with a few more clients and a few servers too. Some may be on a VPN but I think some others may be not. This one will be nice since I don't have to run my own client to poll for responses from prior requests but I figure that is coming too. This connection I just send over the request and then need to have a server wait a good long time for a response. They have to perform a phone call verification with a doctor so it's not very "real time". Mostly it just is matching up my requests with supplied responses and sending them back where they came from. This is basically just an "internet trucking" application delivering and receiving loads.

Are you aware of any standard response that is used from a server. I get the impression these folks don't want one.