NetTalk Central

Author Topic: need help TCP/IP conversation  (Read 29126 times)

Thomas

  • Newbie
  • *
  • Posts: 27
    • View Profile
    • Email
need help TCP/IP conversation
« on: August 20, 2007, 12:24:39 AM »
Hello,
I need some help regarding TCP/IP (NetSimple) conversation. I must send data to a third party via TCP/IP. About the receiver I know nothing but the address, port and protocol. A group of data to send are 1 to 15 kbyte with a unique start and stop byte (uniqueness ensured by the protocol). I must send up to 100 of such groups one after another in a background task without any user interaction.
My problem is, that I don't get back any ackn from the receiver and my fear is that the groups getting mixed up.
Is it better to open the port in sychron mode (but send will always be async) ? Is there a chance that after the send()
I could get an info "all_data_send" ? Which fits better scenarion 1 or 2 ?

scenario 1:
open port
loop
  prepare data
  send
  errorhadling ?
end
close port

scenario 2:
loop
  prepare data
  open port
  send
  errorhadling ?
  close port
end

Any ideas are welcome.
TIA, Thomas

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: need help TCP/IP conversation
« Reply #1 on: August 20, 2007, 06:51:02 AM »
Hi Thomas,

It's important to realize that all TCP/IP comms is asynchronous. And I strongly recommend using the Async open as well.

This means you need a "Window" procedure, because you need Events.
You can of course hide the window ( window{prop:hide} = 1) if you don't want the user to see it.

Once the port is Open, you are free to send as much as you like inside a loop. You cannot however do error handling after a Send. (because things are happening asynchronously). If there is an error then the ErrorTrap method is called.

However if you need to wait for an Ack before sending the next bit then sending in a loop is not for you.  In that case you need to send, and then do nothing. When the ack arrives the .Process method is called. You can check the ack, and send the next packet (and so on.)

The good news is that once you've got the basic structure sorted out, the rest should be pretty easy. Incoming packets can be handled in .Process, Errors can be handled in ErrorTrap.

The NetDemo example is a good place to start. This lets you open a server, and a client, window so you can play around in plain text.

Cheers
Bruce

Thomas

  • Newbie
  • *
  • Posts: 27
    • View Profile
    • Email
Re: need help TCP/IP conversation
« Reply #2 on: August 20, 2007, 08:11:12 AM »
Hello Bruce,
I think I got the whole picture. I've done other NetSimple conversations wich are working pefect. But in these cases both sides client ans server where under my control.
Now I have the prob only to be the Client (Sender). I never ever get an ack back. And it is my responsibility to ensure, that there are never a mixing of data can happen in the stream:
startbyte-mydata1-stopbyte-startbyte-mydata2-stopbyte-startbyte-mydata3-stopbyte... a.s.o.
Can I savely do (metacode) the following (in asyncopensuccessfull) ?
loop k= 1 to count
  bindata= startbyte & mydata[ k] & stopbyte
  ! size mydata 1..15kb
  send()
end

TIA, Thomas
« Last Edit: August 20, 2007, 08:14:41 AM by Thomas »

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: need help TCP/IP conversation
« Reply #3 on: August 20, 2007, 11:02:42 PM »
Hi Thomas,

The biggest problem I always have when talking to servers not under my control, are the things they don't tell you in the docs.

The most common one is that "commands should be terminated with <13,10>." For example in the old modem days the ATZ command was always the rest-modem command. But actually it was ATZ<13,10>.

A good way to progress quickly is to get a working client if you can. Then "snoop" on what's going on (using something like ethereal) and you can usually quickly spot the difference.

the only think you'd need to add to your psudo code below is the setting of bindatalen.

You're not gonna get an ACK as long as you remain in the loop, because you need to get an event to receive the Ack.

The packets you send will arrive in-order, so you don't need to worry about that.

Cheers
Bruce




Thomas

  • Newbie
  • *
  • Posts: 27
    • View Profile
    • Email
Re: need help TCP/IP conversation
« Reply #4 on: August 22, 2007, 09:22:47 AM »
A good way to progress quickly is to get a working client if you can. Then "snoop" on what's going on (using something like ethereal) and you can usually quickly spot the difference.
will I do when I'm on site !

Quote
the only think you'd need to add to your psudo code below is the setting of bindatalen.
;-) thatswhy I called it meta...

Quote
The packets you send will arrive in-order, so you don't need to worry about that.
Fine. BTW, how it is handled within the Dll - every Send() adds a Queue entry internally wich is transfered to Winsocks in a FIFO process ?

Great product and great support, thanx Bruce.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: need help TCP/IP conversation
« Reply #5 on: August 23, 2007, 06:29:44 AM »
>> Fine. BTW, how it is handled within the Dll - every Send() adds a Queue entry internally which is transfered to Winsock in a FIFO process ?

more or less...

Cheers
Bruce