I have an OpenGL application that plots data in real time. I would like to have a background TCP server that will accept data from a client without blocking on a call. The data is originally an array of 2048 doubles. Once this array of data arrives, I need to place it in a circular array buffer that is read from the foreground OpenGL program.

I initially tried the async TCP server code from Microsoft but this code blocks on the listener.BeginAccept.

I thought that this code would operate in the background but obviously not. So I need to run the server in a background thread and not block on a read. I could use a much simpler server since I only have one client at a time to deal with.

Now the circular array buffer is a static class. To write to it it is a simple CircularBuffer.Write(double buffer); The class takes care of all indexes.

So what I need is a thread safe TCP server running in the background which can write to this circular buffer. I assume I might need to have some locking mechanism?

Can you suggest an over approach to this please?

  • 1
    I think you should elaborate more your problem and separate each problem in one question, because there are a lot of concerns to made it work. Maybe this article can help you with TCP server side: blogs.msdn.microsoft.com/pfxteam/2011/12/15/… – Pagotti Jan 16 '17 at 11:50
  • Thanks. Actually the circular buffer is taken care of with a locking mechanism. I just need the tcp side. – Tom Jan 16 '17 at 15:43
  • TCP is quite low level. You might want to think about WCF. – Frank Hileman Jan 16 '17 at 19:56
  • I don't know. I haven't seem any examples about binary data. Seems it's all xml or streaming. But then even then seems pretty inefficient to send biary data. I could be wrong I guess. – Tom Jan 16 '17 at 23:16
  • @Tom I use it with binary data all the time -- you can chose the encoding to some extent. It does not have to be strings. I have found it quite efficient. – Frank Hileman Jan 18 '17 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.