Sunday, July 6th 2008, 6:55pm UTC+1

You are not logged in.

  • Login
  • Register

1

Tuesday, May 6th 2008, 10:46am

redirecting sockets

Hi everybody,

I have a server application that connects an IP video camera and redirects any data from this camera to a client's socket, as shown below:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// _pIOClient is a QIODevice* object wrapping the client's socket

   qint64 n64, m64;
   QByteArray bytes;
   QTcpSocket sckt;

   // connect sckt to another server
   sckt.connectToHost(...);
   // ...

   _pIOClient->write("test 1");

   // ask the server to start the streaming
   sckt.write("PLAY ...");
   // ...

   _pIOClient->write("test 2");

   while (_pIOClient->isOpen()) {
      if (sckt.waitForReadyRead(3000)) {
         bytes = sckt.readAll();
         m64 = bytes.size();
         qDebug("%ld bytes to write", m64);
         if (m64!=0) {
            n64 = _pIOClient->write(bytes.data(), m64);
            qDebug("written %ld of %ld bytes", n64, m64);
         }
      }
   }


The problems are:

  1. The data sent in line 11 ("test 1") are received by the client, but data in line 17 (just after camera has started the streaming) and line 25 are not received by client for some reason.
  2. Application never exits the loop at line 19, even when _pIOClient is not opened (because client has closed the socket).
  3. Application console output is:

    Quoted

    1296 bytes to write
    written 1296 of 0 bytes
    4 bytes to write
    written 4 of 0 bytes
    1296 bytes to write
    written 1296 of 0 bytes
    4 bytes to write
    written 4 of 0 bytes
    ...
    [/list=1]

    And my questions are the following:

    1. Is the network module busy with camera's streaming? is that why client socket does not work? how can I fix it?
    2. Why does application think that _pIOClient is always opened?
    3. Why is m64 set to zero?[/list=1]
  • Go to the top of the page

2

Tuesday, May 6th 2008, 2:41pm

RE: redirecting sockets

you should have a compilation warning like:
warning: format '%ld' expects type 'long int', but argument 2 has type 'qint64'

EDIT: but it doesn't seem to be a problem
Nicolas

This post has been edited 1 times, last edit by "Nicolas SOUCHON" (May 6th 2008, 2:52pm)

  • Go to the top of the page

3

Tuesday, May 6th 2008, 2:49pm

RE: redirecting sockets

Yes, you are right, I have this warning. Anyway this is not my main problem, in fact I have removed the 'qDebug' lines.

Actually, my problems are only two:

  1. Is the network module busy with camera's streaming? is that why client socket does not work? how can I fix it?
  2. Why does application think that _pIOClient is always opened?
    [/list=1]

    Best regards,

    Manuel
  • Go to the top of the page

4

Tuesday, May 6th 2008, 2:54pm

RE: redirecting sockets

how and where is your loop implemented?

seems me your loop is blocking

EDIT:

better than waitForReadyRead would be to use
- the signal QIODevice::readyRead() for the camera's device
- the signal QAbstractSocket::error( QAbstractSocket::SocketError ) for the client's socket
Nicolas

This post has been edited 4 times, last edit by "Nicolas SOUCHON" (May 6th 2008, 3:05pm)

  • Go to the top of the page

5

Tuesday, May 6th 2008, 9:59pm

RE: redirecting sockets

I don't know about #1 but for #2 the reason the application thinks that _pIOClient is always opened is because I don't see where you close it
  • Go to the top of the page

6

Wednesday, May 7th 2008, 8:32am

RE: redirecting sockets

Quoted

I don't know about #1 but for #2 the reason the application thinks that _pIOClient is always opened is because I don't see where you close it


Remember that my application is a server. This _pIOClient object is a socket opened by a client. When client closes this socket, the server does not exit the loop.

Quoted

how and where is your loop implemented?

seems me your loop is blocking


I have a class that inherits QTcpServer. For every incoming connection (every time the client opens a socket), a thread is launched. This thread runs the sample code explained in the first post. Maybe the problem is that this thread can manage the camera socket but not the client's one, isn't it?

Quoted

better than waitForReadyRead would be to use
- the signal QIODevice::readyRead() for the camera's device
- the signal QAbstractSocket::error( QAbstractSocket::SocketError ) for the client's socket


Can I implement this kind of behaviour in every single thread? or should I have to use several threads redirect one camera to a client?
  • Go to the top of the page

7

Wednesday, May 7th 2008, 11:18am

RE: redirecting sockets

show code to see how your loop is implemented

ie: not only the loop, but environment

if the loop is in a slot or a function called from a slot,
probably no other slot can be executed because the loop is blocking

QTcpSocket is signals/slots based, which permits you to avoid use of threads
Nicolas
  • Go to the top of the page

8

Monday, May 12th 2008, 5:59pm

RE: redirecting sockets

Quoted

Originally posted by Nicolas SOUCHON

QTcpSocket is signals/slots based, which permits you to avoid use of threads


Does it mean that I can manage all the connections from clients to cameras without creating any new thread?
  • Go to the top of the page

9

Monday, May 12th 2008, 6:20pm

RE: redirecting sockets

yes

except if some treatment is too long and freezes others connections or interface
Nicolas

This post has been edited 1 times, last edit by "Nicolas SOUCHON" (May 12th 2008, 6:24pm)

  • Go to the top of the page

Rate this thread