Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. BSD Socket wrapper with QT
Servers for Qt installer are currently down

BSD Socket wrapper with QT

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mrluzeiro
    wrote on 11 Aug 2014, 15:13 last edited by
    #1

    Lets say that I have a project, that:

    • must be multiplataform (Win & Linux)
    • the source code must be based in BSD sockets syntax like.

    Is there any suggestion how can I wrapper QT socket functions to work like BSD sockets?
    Probably someone already implement a BSD socket library based on QT.

    The main propose is that I would like to add a new external BSD library (compatible with Win & linux .. .a .lib..obj..dll.. :S ) and must keep my source with the BSD socket include functions "language".

    Suggestions?
    Thanks!

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gyll
      wrote on 11 Aug 2014, 15:24 last edited by
      #2

      Qt sockets have a method to access their underlying raw socket,
      e.g. qudpsocket.socketDescriptor(), you might want to use that one to write your wrapper.
      doc here: https://qt-project.org/doc/qt-5/qabstractsocket.html

      here's an example to set the time to live (TTL) value:
      @ QUdpSocket socket;
      int port=10000;
      int msg_ttl=20;
      socket.bind(port);
      qintptr rawSocket=socket.socketDescriptor();
      int sockErr=setsockopt(rawSocket, IPPROTO_IP, IP_TTL, (const char*)&msg_ttl, sizeof(msg_ttl));
      // std::cout<<"Setsockopt error code: "<<WSAGetLastError()<<std::endl;
      assert(!sockErr);@

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andreyc
        wrote on 11 Aug 2014, 16:10 last edited by
        #3
        1. BSD sockets is a "standard" communication C-library for Unix and Linux. I think Windows has a compatibility layer for BSD sockets.
        2. Qt is C++ library and it uses BSD sockets on Unix and Linux and OS X
        • Example 1

        A simplified example of BSD sockets initialization for server and client. I skipped all address resolving part.
        @
        server = socket(...); /* create socket /
        bind(server, ...); /
        bind address to socket /
        listen(server, ...); /
        listen for client */
        @

        @
        client = socket(...); /* create socket /
        connect(client, ...); /
        connect to server */
        @

        • Example 2

        A simplified Qt tcp server and client initialization example
        @
        tcpServer = new QTcpServer;
        @

        @
        QTcpSocket socket;
        socket.connectToHost(serverName, serverPort);
        @

        Do you need C++ or C library ?
        Is your idea to replace code in example 2 with code as in example 1 ?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrluzeiro
          wrote on 11 Aug 2014, 17:17 last edited by
          #4

          I must use the BSD sockets header functions "syntax" like your Example1. So this is a C library.
          "In background", that BSD sockets header functions, should be implemented using QT sockets (like you describe in Example 2).

          If that doesn't exist (some one implemented it before opensource), I will need to implemented it.. or.. use some other additional external library that implements the BSD sockets (for windows in that case.. because for linux it is "built in..")

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andreyc
            wrote on 11 Aug 2014, 17:33 last edited by
            #5

            I don't think that BSD sockets on top of Qt exists.
            Windows implements the BSD sockets with some addition functionality.
            For example "socket()":http://msdn.microsoft.com/en-us/library/ms740506(v=vs.85).aspx

            If you have to use BSD sockets then it is easier to implement a layer on top of Windows Sockets Api to hide its "WSAStartup() and its relatives":http://msdn.microsoft.com/en-us/library/ms742213(v=vs.85).aspx and use native BSD sockets on Linux, etc.

            1 Reply Last reply
            0

            1/5

            11 Aug 2014, 15:13

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved