1

I'm a first time poster but long time user and since this community helped me out often already I hope you can once more.

My problem is the following: I'm building a machine that is controlled over a network, it has a camera attached to it that is on a XY-table. I need to be able to control this table and therefore the camera in real time, but the livestream of the camera picture is very laggy and unresponsive.

I'm using .NET and WCF for the network part, everything is running on the same computer currently but yet still there is a huge delay (~500/1000ms) between camera and showing the picture on screen.

On a different note, I also have the problem that the server can't send and recieve messages at the same time apparently, eg. the server recieves a command and needs to send a picture which causes him to drop the command and only send the picture.

I hope somebody has experience with those problems, thank you in advance!

My Service:

   <ServiceBehavior(ConcurrencyMode:=ConcurrencyMode.Single,
                    InstanceContextMode:=InstanceContextMode.PerSession,
                    IncludeExceptionDetailInFaults:=True)>
   Public Class clsNetworkService
     Implements INetworkService

  Private m_Connection As INetworkClient

Public Sub Login(pi_sUserName As String) Implements INetworkService.Login

    m_Connection = OperationContext.Current.GetCallbackChannel(Of INetworkClient)

Client:

m_ChannelFactory = New DuplexChannelFactory(Of INetworkService)(m_Client, "ChatServiceEndpoint")
m_Server = m_ChannelFactory.CreateChannel()

Try
  m_Server.Login(Environment.UserName)
Catch ex As EndpointNotFoundException 

End Try

The image transfer happens by handing a memorystream to the client which he then converts back into a bitmap. The bitmap is then being displayed in a picturebox. All methods are declared as one way because not doing so caused problems as well.

dralois
  • 11
  • 2
  • [Streaming over HTTP with WCF](https://blogs.msdn.microsoft.com/endpoint/2010/11/24/streaming-over-http-with-wcf/) – ldgorman Nov 30 '16 at 09:28
  • [Live c# video streaming webcam server and client](http://technicalstuffhopefullyuseful.blogspot.ch/2012/06/live-c-video-streaming-webcam-server.html) – ldgorman Nov 30 '16 at 09:30
  • You can use multiple channels to receive the images and send the commands, then it won't block eachother anymore. – Rabban Nov 30 '16 at 09:34
  • 1
    *how can I improve my code?* - I don't know. I haven't seen your code. Why don't you show it to us :) – tom redfern Nov 30 '16 at 09:58
  • @Rabban how would that work? The client is recieving the images from the server once they are created, but the server only has one callback channel I thought..? – dralois Nov 30 '16 at 10:12
  • @idgorman I actually used the second example as a template for my own functions, the image transfer works great, just the delay is a problem. – dralois Nov 30 '16 at 10:14
  • @dralois if you use the `System.ServiceModel.ClientBase` you can call `base.CreateChannel()` and use this for your commands. – Rabban Nov 30 '16 at 10:23
  • @rabban I don't quite understand how to use this, the client uses a `DuplexChannelFactory` to connect to the service, the service saves the connection by using `OperationContext.Current.GetCallbackChannel `. Whenever I send a picture to the client the server calls a function on the client side to recieve the image. It seems like the server can however only do one thing, handle a request by the client or send something to the client by himself, which results in dropping the request most of the times. – dralois Nov 30 '16 at 10:32
  • 1
    As @TomRedfern pointed, without code, without help :) It's difficult to point any issue without seeing your code. Anyway, I can sugest you to read about the way your service is transporting data: http://stackoverflow.com/questions/4043683/wcf-httptransport-streamed-vs-buffered-transfermode and also, for stream can be used other options than WCF, like a direct socket or Microsoft Expression Encoder SDK. – Ricardo Pontual Nov 30 '16 at 10:51
  • @dralois even the ChannelFactory has a method `CreateChannel()` – Rabban Nov 30 '16 at 10:59
  • @TomRedfern I included code in the description now, sorry about not doing so in the first place. If more information is needed I will included that as well. – dralois Nov 30 '16 at 11:00
  • @RicardoPontual Code is now included, if more is needed I will provide it as fast as possible, thank you for letting me know though! – dralois Nov 30 '16 at 11:01
  • @Rabban As you can see in the now included code I already use that, but I still don't understand why I would create several channels since I'm sending the picture to the client and not the other way round (client calls functions on the server, server sends pictures to the client). – dralois Nov 30 '16 at 11:03

0 Answers0