Results 1 to 5 of 5

Thread: [Qt] File transfering and others

  1. #1
    Join Date
    Dec 2009
    Posts
    23
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default [Qt] File transfering and others

    Hello there,

    I am creating a advanced Chat with client and server. I want to create file transfering into application. For example every client connected in chat, can choose and send a file to the server or choose the user online on the chat and send a file to him. How can I do it? I have seen few codes but I don't know how can I use it. I think that file transfering can be done easier than methods which I saw. I have seen some code which is easy to implements, to use and not too long, but I can't find it again.

    Client sending message to the server, send packets to server, in every "message to server" is header of type message (like user connected, user send message, user disconnected..). I send that method before the main message like: "type|main message". Server interprets that message from client and looks at "type" so server knows what do. But if I send file how can I inform that I will send a file?

    Can you give me some code of implement file transfering?

    Best regards.

  2. #2
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: [Qt] File transfering and others

    Judging from Your question I think Your solution won't work on actual network.
    You probably testing Your server/clients in the LAN network and everything is working fine, but on actual network You need to use NAT Traversal. The problem is that most users are behinde routers (they don't have external IP assigned to them) so You don't know IP of particular user/client in LAN and thus can't send anything to them (not only a file but a messages also - if Your server supports sending messages arrived to the server while user was off-line).

    Example 2 users use Your clients, they are behind router with internal/LAN Ip's 192.168.0.2 - 192.168.0.3. How do You send a file file/message to one of them?

    See/study udp hole punching, UPnP, NAT-PMP, NAT traversal etc. Or simply use ready solution/class.
    Sorry for not specific answer but your question is broad.
    Last edited by Talei; 5th November 2010 at 18:39. Reason: spelling corrections
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  3. #3
    Join Date
    Dec 2009
    Posts
    23
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [Qt] File transfering and others

    Sending messages works FINE. I don't have problems with that, all works good, I can send messages through LAN. But I don't know how transfer file from client to server

  4. #4
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: [Qt] File transfering and others

    Are You sure that You can send message to client that is on different LAN? Example 1st client external ip xxx.xxx.xxx.xxx LAN IP 192.168.0.2 sends the data to 2nd client yyy.yyy.yyy.yyy LAN IP 192.168.0.2. Sorry for asking but net traversal is much harder then simply sending file so that's why I'm asking.

    You have client Ip then simply send the data using QSocket or whatever class You are using.
    Basically You read the data, prepare a header (it's not TCP header but Your own) with file size - add (first on data part) information about current position of the data chunk (see max data size for tcp), send small chunk, if EOF finish. Client receive the data, parse header, read file size, counts current file size (present with data received - parse it out), then if (current size) == (file size) finish.
    See chunked transfer encoding of the HTTP proto. You can do the same, simply prepare different header that will meet Your needs.
    At least this is how I would go about doing something like this so if I'm wrong correct me
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  5. #5
    Join Date
    Dec 2009
    Posts
    23
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [Qt] File transfering and others

    yes, I am sure because I tested it. OMG. I want only good code example.. Only this.

Similar Threads

  1. Replies: 3
    Last Post: 1st November 2010, 16:33
  2. Replies: 3
    Last Post: 28th March 2009, 15:37
  3. transfering items from one model to the other
    By ru_core in forum Qt Programming
    Replies: 4
    Last Post: 27th June 2008, 08:44
  4. Replies: 3
    Last Post: 25th May 2007, 07:49
  5. Replies: 2
    Last Post: 23rd May 2007, 03:51

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.