3

I am working on Connecting an Embedded Circuit board to PC via TCP.

The board contains a chip which, sadly, doesn't generate any interrupt on Receiving data. But it does generates an interrupt on receiving "Keep-Alive" signal.

Currently I have to poll for data. Instead, I am thinking that, I will send data from PC and then a KeepAlive Signal. Whenever a KeepAlive is received, I will read data too. I do understand that this might generate false alarms but it's better than continuous polling.

I observed a Keep-Alive packet on Wireshark, it has One byte of Data and it is "00". Keep Alive Signal on Wireshark

And then I tried to send TCP Packet with Data as "00": Simulated Keep Alive Signal

I can see, Only Flag Section is different.

I got Two questions:

  1. (Broadly) How to manually send a Keep-Alive Signal?
  2. How to change that flag setting? (Flags in send and sendto are different)

Update: I have tried RawSockets, but that didn't help me or I missed something. I just change Flag to ACK in RAW Sockets header.

Swanand
  • 4,027
  • 10
  • 41
  • 69
  • @mvg answer is correct. Also depending on why you want keepalives, my answer here is possibly of interest: http://stackoverflow.com/questions/5338352/asyncsockets-and-silent-disconnections/5338459#5338459 – Ben Oct 01 '13 at 12:19
  • @Ben I want KeepAlive to generate an interrupt on my Microcontroller board and that too whenever I want, Not periodically! – Swanand Oct 01 '13 at 13:45
  • 1
    doesn't an ordinary TCP or UDP packet generate an interrupt? Why does it have to be a keepalive? – Ben Oct 01 '13 at 13:56
  • @Ben That's the problem... It generates Interrupt on KeepAlive only... So my plan is send data and then send a KeepAlive so that I would know when to read! – Swanand Oct 02 '13 at 06:20
  • I'm finding this hard to believe. A keep-alive segment is just an ordinary TCP segment containing an ACK for a segment that has already been received. If you get an interrupt on those, you should certainly get one on segments containing data. – user207421 Oct 02 '13 at 07:11
  • 1
    @SwanandPurankar Are you sure that the usual interrupt is not just being masked or handled elsewhere? – Ben Oct 02 '13 at 07:39
  • @EJP Yes, That Chip has this specific scenario!! I have tested and confirmed! And As Keep Alive is "kind-of" normal TCP Message, That's why I am asking how to generate Keep Alive signal whenever I want! – Swanand Oct 02 '13 at 08:20
  • @Ben Yes... Only Keep Alive generates Interrupt... There are events only for Connection, Keep Alive and Disconnection! – Swanand Oct 02 '13 at 08:22
  • I suspect you just need to go and read your documentation. There must be some way you can find out when data is available. Does a UDP packet generate a "connection" interrupt? – Ben Oct 02 '13 at 08:30
  • Where do you read that about the keepalive interrupt? I see the API supports the [`select` call](http://software-dl.ti.com/ecs/simplelink/cc3000/public/doxygen_API/v1.11/html/d2/d21/group__socket__api.html#gaf3c381842cceb163ed0be29521308fab), so at least for an idle application, using that instead of polling should be fine. And from [what I read on unsolicited events](http://processors.wiki.ti.com/index.php/CC3000_Host_Programming_Guide#Unsolicited_Events), even those need some acive polling via `hci_unsolicited_event_handler`. Does this help? – MvG Oct 02 '13 at 08:37

1 Answers1

3

RFC 1122 section 4.2.3.6 might be worth reading.

It states that keepalive is an optional feature of the TCP implementation. It also states that keepalive signals should be limited to at most one every two hours. So manually emitting one from your application isn't a desired feature in general.

Furthermore, it describes details about the implementation, in particular pointing out the sequence number involved. This is one difference visible in your screen shots which you apparently failed to notice: the real keepalive packet has a very high relative sequence number, which is simply the unsigned representation of -1. To reproduce this with raw sockets, I think you'd have to somehow get your hands on the current TCP sequence number of the existing connection. Haven't worked enough with RawSockets to know details on how to do this.

The supported means to have the system send keepalives periodically is using the SO_KEEPALIVE option. But that won't be of much use to emit such a signal at a specific moment in time, I think.

Community
  • 1
  • 1
MvG
  • 57,380
  • 22
  • 148
  • 276
  • @swanandPurankar, You may wish to set the desired keepalive interval with SIO_KEEPALIVE_VALS, as the default is 2 hours. – Ben Oct 01 '13 at 12:21
  • I do understand that One should not transmit KeepAlive signal. But This will be part of my private network and I can load it with KeepAlive frames.That's why I need send KeepAlive whenever I want! And by the way @Ben has suggested, I won't be able to do so! Still, Thanks... I will see if this thing with Sequence number works or the document! – Swanand Oct 01 '13 at 13:44
  • @SwanandPurankar: Without looking at the details, this sounds like you might have to implement your own TCP implementation in user space, on top of raw sockets. Not a thing I'd look forward to, but sounds like the most viable solution I can imagine. – MvG Oct 01 '13 at 13:55
  • @MvG Updated some details of the system! – Swanand Oct 02 '13 at 06:24