Results 1 to 6 of 6
  1. #1
    bachma7 is offline Member
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Default multi clients connect to udp server

    hi every body,i have a question- i programing UDP server to download file,it 's work but it can serve only one client one time, how could i create a udp server that can serve a lot clients at the same time. thank you very much.

  2. #2
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Why are you using UDP?
    Moving a file is exactly why TCP was invented.

    If you use UDP, you have to implement all the error correction and out of order stuff yourself.

  3. #3
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    6

    Default

    Essentially, you have to "manage it". That's the thing about UDP.

    I think you have a couple of options. The first is, just have a single DatagramSocket object. This could be a simple option if the result of every received datagram is to immediately send out a corresponding packet. Obviously, you check the packet to see which client send the request, and send back a packet to that client.

    Java also supports the pretend notion of "connecting" datagram sockets to a client (i.e. limiting a DatagramSocket object to sending/receiving from a particular client). So you could have a DatagramSocket object per client that you send to, and use a traditional server model of having worker threads that send the data back. This would be a better option if the server needs to "think" a little after receiving each request before sending back the response.

  4. #4
    bachma7 is offline Member
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Default

    Quote Originally Posted by neilcoffey View Post
    Essentially, you have to "manage it". That's the thing about UDP.

    I think you have a couple of options. The first is, just have a single DatagramSocket object. This could be a simple option if the result of every received datagram is to immediately send out a corresponding packet. Obviously, you check the packet to see which client send the request, and send back a packet to that client.

    Java also supports the pretend notion of "connecting" datagram sockets to a client (i.e. limiting a DatagramSocket object to sending/receiving from a particular client). So you could have a DatagramSocket object per client that you send to, and use a traditional server model of having worker threads that send the data back. This would be a better option if the server needs to "think" a little after receiving each request before sending back the response.
    thanks for your relpy. i create a loop which receive a connection from once client, then i create a thread to transfer file to that client while the loop go back to listen other connection.
    but the problem is when i create a thread, program said that "address is used", but which my knowledge,a UDPserver can communicate with many clients at the same socket. please help me!!

  5. #5
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    6

    Default

    I wonder if you could post appropriate snippets of your code, with the exact line where you're getting "address is used" (plus the actual, verbatim error).

  6. #6
    kirbushok is offline Member
    Join Date
    Dec 2008
    Posts
    1
    Rep Power
    0

Similar Threads

  1. how to connect a server to multiple clients?
    By azhar in forum Networking
    Replies: 15
    Last Post: 03-22-2010, 12:54 PM
  2. Multi Client/Server Chat Question
    By Kodak07 in forum Networking
    Replies: 3
    Last Post: 03-29-2009, 10:50 PM
  3. SSL Server with authentication of clients
    By zoltan in forum Networking
    Replies: 0
    Last Post: 10-14-2008, 11:27 PM
  4. blocked between server and clients
    By ibtehal in forum Networking
    Replies: 6
    Last Post: 07-17-2008, 12:30 AM
  5. Replies: 0
    Last Post: 04-07-2008, 08:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •