Results 1 to 6 of 6
  1. #1
    ShadowWalker is offline Senior Member
    Join Date
    Mar 2013
    Location
    Greece
    Posts
    183
    Rep Power
    7

    Default Discussion about chat server protocols

    Greetings

    (I hope it's ok to post it here :P )

    I am still working on chat application and I am tring to make things little more complicated/challenging, so i decided to add private messages via clients with sound and image support something like skype. Now my question is not exactly about java but more about the protocols which the servers has to implement. I have an idea about how the things supposed to be but i am not entirely sure that is the right or the most efficient way to do it.
    So let me describe what i think and i would like to hear your opinion about this situation.

    Let's say we got 2 clients . Client1 and Client2 and just for the example let's say that the client1 want to start a private chat session with Client2. So he send him an invitation and if the Client2 approved it , the private chat session begin. Now let's see what is happening into the server. First the server open a new socket with Client1 (an inputStream and outputStream) just for plain text (same thing will happened for sound and video too but let's keep it simple for now) , when the sockets is opened then the server send to Client2 a "command" to answer if he want to approve the invitation. If he does then the server open a new Socket for client2 (same like Client1 ... inputStream and so on..) when both of the sockets are ready then the server connect the inputStream of the Client1 with the outputStream of the Client2 and the outputStream of client1 with the inputStream of Client2 and then the process is clear.
    In conclusion for each private chat session i will need first of all a thread for the current session and then 3 sockets with 6 inputStream and 6 outputStreams .. 2 for sound , 2 for video and other 2 from plain text and all this for each client, of course different ports for each socket and each private chat session..

    The image above shows the sound implementation in the server and the same thing will happened to video and plain text too

    Discussion about chat server protocols-finalservermodel.png

    So it's my idea or this is going to be too damn messy and difficult to implemented? is the only way to do it? and of course i don't want to take anything already finished for example a 3 party library and add them into my app.. I would like to make my own for practise..

    Thx in advance

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Discussion about chat server protocols

    "If he does then the server open a new Socket for client2"

    The server opens a new socket? That's not how it generally works; clients connect to servers, servers do not connect themselves to clients.

    I get the idea that what you are after is actually more like a peer-to-peer connection. As in client 1 and client 2 open up a direct temporary communication line to each other to share data; in such a scenario the server doesn't need to actually be in between to broker data between the two clients. Am I right?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    ShadowWalker is offline Senior Member
    Join Date
    Mar 2013
    Location
    Greece
    Posts
    183
    Rep Power
    7

    Default Re: Discussion about chat server protocols

    Quote Originally Posted by gimbal2 View Post
    "If he does then the server open a new Socket for client2"

    The server opens a new socket? That's not how it generally works; clients connect to servers, servers do not connect themselves to clients.
    Yeah I wasn't clear sorry :P . But you got the point :P

    Quote Originally Posted by gimbal2 View Post
    I get the idea that what you are after is actually more like a peer-to-peer connection. As in client 1 and client 2 open up a direct temporary communication line to each other to share data; in such a scenario the server doesn't need to actually be in between to broker data between the two clients. Am I right?
    Yeah that's exactly what i want to do.. Really doesn't need the server between them? but then one of them must have a static ip address so he will listen for the connection and the other one will open the socket right? I start to feel like i should go to check the socket api once more :P

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Discussion about chat server protocols

    That's the gist of it yes. Its far from easy to achieve though.

    IMO its simpler to stick with one connection per client, make the server the broker for all communication between clients and instead break down your communication protocol into different types of messages.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    ShadowWalker is offline Senior Member
    Join Date
    Mar 2013
    Location
    Greece
    Posts
    183
    Rep Power
    7

    Default Re: Discussion about chat server protocols

    Quote Originally Posted by gimbal2 View Post
    That's the gist of it yes. Its far from easy to achieve though.
    That's going to this one : Really doesn't need the server between them?
    or to this one : but then one of them must have a static ip address so he will listen for the connection and the other one will open the socket right?

    Quote Originally Posted by gimbal2 View Post
    IMO its simpler to stick with one connection per client, make the server the broker for all communication between clients and instead break down your communication protocol into different types of messages.
    i could make the server to show the messages like private only to the person that has been sended and all shows inside the same Area but I would like to have private messages to onother JFrame (or Scene for javaFX) but even though the plain text isn't the problem.. the problem came up when i start to thing about voice and image..

    Every resource you can provide me about peer to peer connection would be helpful.. i will make my research on google too :P but just in case..
    If i haven't understand something correct please let me know

  6. #6
    Xen
    Xen is offline Member
    Join Date
    Jan 2015
    Posts
    86
    Rep Power
    0

    Default Re: Discussion about chat server protocols

    The difficulty with peer to peer is of course that you run into firewall issues and then you need UPnP and so on. I would think through a server is best and a multi-layered protocol is best for that but it means you get bandwidth issues at your server perhaps. Normally probably when you make such a system you would initially or ideally layer the text communications and the setup of several other connections through the server, which would then prompt the clients to open UPnP ports, which would then prompt the clients to set up a connection with each other for audio and video.

Similar Threads

  1. My chat server
    By Xen in forum Threads and Synchronization
    Replies: 3
    Last Post: 01-18-2015, 04:04 PM
  2. Help Needed! Android chat - pc chat server
    By thornt in forum Android
    Replies: 3
    Last Post: 04-13-2012, 12:50 PM
  3. Chat Server
    By mrbrendano in forum New To Java
    Replies: 1
    Last Post: 09-19-2011, 11:08 PM
  4. midlet chat server
    By nfitte in forum Networking
    Replies: 0
    Last Post: 07-09-2009, 09:08 AM
  5. Replies: 1
    Last Post: 12-20-2008, 09:28 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
  •