This discussion is archived
3 Replies Latest reply: Jul 6, 2012 1:05 PM by DrClap RSS

Handle communication priority for client with two connections

tmazight Newbie
Currently Being Moderated
Hi,

I'm writing a server where I have to accept connection on two ports, 2 Socket for each client.

One socket have more priority than the other, and the two of them will write on the same file.

How can i make an architecture with the less threads possible(A lot of client, perhaps 600), and be sure that while i have messages on the priority socket, i give it the priority to right on the file.

best regards.
  • 1. Re: Handle communication priority for client with two connections
    gimbal2 Guru
    Currently Being Moderated
    a) use the NIO API to build your server; that will open up the possibility to meet your "less threads possible" requirement
    b) build your software such that it meets the other requirements

    You know what you want; as a developer you should be able to translate that to a working solution. If you can't then you may be trying to run before you have learned to walk.

    When you have specific code questions you can always drop in and ask for help with it.
  • 2. Re: Handle communication priority for client with two connections
    tmazight Newbie
    Currently Being Moderated
    Thanks Gimbal,

    I have two more questions plz,

    it is possible to let one thread handle two connections of a client on two different ports(one for simple data, the other for urgent) by switching on the two sockets of the two connections without lost of messages? if it is not possible and i guess it's the case,
    then is there an issue to identify the incoming connections, to regroup the socket for urgent data and socket for simple data for each client and give priority for the urgent data (knowing that i will have two selector one for each server Socket).

    I know that my questions are philosophical, that's because I'm new to network programming and i have to take a decision: NIO or IO.

    Thanks again :)
  • 3. Re: Handle communication priority for client with two connections
    DrClap Expert
    Currently Being Moderated
    tmazight wrote:
    it is possible to let one thread handle two connections of a client on two different ports(one for simple data, the other for urgent) by switching on the two sockets of the two connections without lost of messages? if it is not possible and i guess it's the case,
    Loss of messages will only happen if you don't write your code correctly. So if you want a single thread to handle both connections, you have to ask yourself what you want to happen if the server is processing low-priority data and then some high-priority data becomes available. Is the server allowed to process both of them at the same time? If not, what is your upper bound for the time that the high-priority data connection can wait before being processed?
    then is there an issue to identify the incoming connections, to regroup the socket for urgent data and socket for simple data for each client and give priority for the urgent data (knowing that i will have two selector one for each server Socket).
    There shouldn't be. If you write the code correctly then you keep track of which connections belong to which client.
    I know that my questions are philosophical, that's because I'm new to network programming and i have to take a decision: NIO or IO.
    I wouldn't call them "philosophical". They are just symptomatic of you doing things in the wrong order. NIO versus IO is a low-level design detail, which you shouldn't really be considering until you have a high-level design, or architecture, in your hand. Nothing which you asked there has any bearing on the NIO versus IO decision.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points