Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am an I-Series (AS/400) programmer and we have developed multiple socket programs between the I-Series and the GUI web front end (.net) that use a fixed length on the Send and Receive commands. I have created a variable length proof of concept on the I-Series (Server-Client) that works. My problem is knowing how to help my .net programming friends in creating the .net code that is needed to do variable length socket communications. Can you help explain what to do or the syntax for the commands? I'm not sure if I am using the correct jargon? Thanks! Scott Nance
Posted

I'm not sure if understood properly. You need to syntax for commands to use in .net application which communicates with I-Series stuff (not really sure what is this) via sockets. Socket datagram length have to be constant so all the commands shouldn't be longer than that value, right? If that so, please specify what kind of commands your friends are going to implement. Is this some data access (query-like commands) application or some administration managing app...
 
Share this answer
 
I must disagree with helianthus87. Socket datagram lengths do *not* have to be constant, and therein lies the issue. Consider a socket connection to be a stream, or pipe whose other end happens to be miles away. You need to package your data with either some delimiter(s) you can recognise when scanning the stream or a header that includes a length field. Transmission is easy - just package the message data with header or delimiter(s) and send. The socket implementation will take care of chopping it up into transmission units if necessary (or even welding together adjacent little chunks). On the receive side, how to do it depends on which option you chose above. For delimited, the basic process is:
while (data_available(socket))
  {
  read a byte and append to local buffer;
  if it was a end-of-message mark
    process the buffered message;
  }

For length-delimited:
for (length_of_header)
  read a byte into header buffer;
for (length_of_rest_of_message)
  read a byte into message buffer;
process message;

My personal preference is for length-delimited, for a couple of reasons:
1. It's data transparent. You don't have to make sure your data stream doesn't include whatever you've chosen as a delimiter.[1]
2. Once you've got a header, you will find all sorts of other things you can usefully put there.

Cheers,
Peter

[1] Many many years ago (mid '70s) I worked on a message switch for a major airline. Their telex replacement used torn-tape message delimiting: NNNN = end of message, ZCZC = start of message. That all worked brilliantly until the Polish Symphony Orchestra went on a world tour! :laugh:

[edit] had start and end swapped. It's been a while...[/edit]

[@helianthus87] From the original question, I thought the OP had the I-series side working, and just needed something to tell his .NET colleagues. I could go on about blocking and non-blocking sockets and all sorts of such, but {my} life's too short. :)

Remember to vote, and accept good answers.
 
Share this answer
 
v2
Comments
helianthus87 1-Sep-10 2:53am    
I know some basics about sockets, streamming buffers etc. so thats why i was asking about this. Dunno anything about I-Series architecture so thought thats the reason of such solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900