A
Amit
Hi
I am developing an application in C#. The application creates a
TCPListener object and listens to (incoming) data on a particular
port. A simulator hardware writes data to this port. My application
reads the data and process it and generates some results for display.
The TCPListener object waits for incoming data in a background thread.
The amount of data that is being written is large (around 100 KBytes
in one go). The thread listening for incoming data does not do much
processing. It allocates a buffer of large enough size and waits for
some data to be written on the port (TCPListener.Read() ). Once the
data arrives, it resizes the buffer to the size of the data written
and enqueues it in a Queue object. It then sets an AutoResetEvent to
which other thread is waiting. (That thread then dequeues the data and
processes it).
The hardware is expected to write data in multiple of 4 bytes. If the
number of bytes written to the port is not multiple of 4 then it is
error condition. I am observing that sometimes the application does
not recieve the data of size which is multipe of 4. I am believing
that the hardware is producing correct application data. However,
there is a synchronisation issue for the software application. Before
the previous read is complete, the hardware seems to write new data.
Is this possible? If yes, then how does windows socket mechanism
handle it? Does it buffer the new data internally and then make it
available to the application once the previous read is over? I need
some clarity here. Can anyone explain how the underlying windows
socket mechanism work when there is a simultaneous read/write to an
application port?
Thanks in advance
Best regards
Amit Dedhia
I am developing an application in C#. The application creates a
TCPListener object and listens to (incoming) data on a particular
port. A simulator hardware writes data to this port. My application
reads the data and process it and generates some results for display.
The TCPListener object waits for incoming data in a background thread.
The amount of data that is being written is large (around 100 KBytes
in one go). The thread listening for incoming data does not do much
processing. It allocates a buffer of large enough size and waits for
some data to be written on the port (TCPListener.Read() ). Once the
data arrives, it resizes the buffer to the size of the data written
and enqueues it in a Queue object. It then sets an AutoResetEvent to
which other thread is waiting. (That thread then dequeues the data and
processes it).
The hardware is expected to write data in multiple of 4 bytes. If the
number of bytes written to the port is not multiple of 4 then it is
error condition. I am observing that sometimes the application does
not recieve the data of size which is multipe of 4. I am believing
that the hardware is producing correct application data. However,
there is a synchronisation issue for the software application. Before
the previous read is complete, the hardware seems to write new data.
Is this possible? If yes, then how does windows socket mechanism
handle it? Does it buffer the new data internally and then make it
available to the application once the previous read is over? I need
some clarity here. Can anyone explain how the underlying windows
socket mechanism work when there is a simultaneous read/write to an
application port?
Thanks in advance
Best regards
Amit Dedhia