Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: server/client communication problem

  1. #1
    Junior Member
    Join Date
    Dec 2018
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default server/client communication problem

    Hello.
    I have simple question relating nio and would like ask and get answer in this thread.
    I had such task - to create nio server-multiclient app, where one client could send message directly to another client. What it could mean? Is it possible?
    Whether it means to use server as intermediary - that is client write message and end-client name to buffer - then server read it to socketchannel- here server define the name of client to send original message - and then socketchannel write it buffer - that it is read by end-client??
    How solve such task? Thanfull in advance!

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: server/client communication problem

    One way for direct client to client would be for one of the clients to use a ServerSocket that the other client would connect to.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2018
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: server/client communication problem

    Anyway the client should connect to any other client throught the server (i.e. ServerSocket - ServerSocketChannel). So why it is direct - what is indirect?
    I did not created no socket apps (server-client) untill now, even in java-io, moreover in nio.
    The most disturbing is acceptance moment - should serversocketchannel after opening provide Accept SelectKey - after which opened SocketChannel (automatically) connects to serversocketchannel?!
    In this way all socketchannels in multiclient app - should use this one server acceptance selectkey.
    Then this key is removed - and we use readselectkey?! If socketChannel write some info to buffer then this read selectkey should be exploited?!
    Or how? Should I register manually accept and read selectkey with selector?
    But looking at that simple example - Create server with Java ServerSocketChannel (no selector) -
    just one client- SocketChannel clientChannel = serverChannel.accept();
    or should I put it in some loop to create several ones?[COLOR="Silver"]

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: server/client communication problem

    I haven't used NIO for client/server examples, so I can't recommend what classes and methods to use.

    Here's an example I found a while back:
    http://crunchify.com/java-nio-non-bl...ava-nio-vs-io/
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2018
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: server/client communication problem

    I have used to launched 2 of such examples - one of them was crunchify one -
    indeed just server to be launched -
    Connecting to Server on port 1111...
    No more.
    The other example was of thread wrapped - it worked by provided code.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: server/client communication problem

    Have you solved your problem now? If not post the code you are working with and explain what happens and what you want it to do.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2018
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: server/client communication problem

    I did not try. As this task was earlier indeed I would be glad to resolve it anyway. But I want to know does this example (crunchify.com) shows the same output on somebodies else pc- just about server starting?! It also should be noted that there was option to implement this multiclient server with "direct messages" with IO or other way. So probably it would be fine to try it with io - but if then try to use nio - all complexities of nio would arize again...

Similar Threads

  1. Server/Client Applet- Connection Reset Problem
    By CD8ED in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 16th, 2013, 02:49 PM
  2. server/client communication problem
    By perl0101 in forum Java Networking
    Replies: 8
    Last Post: May 24th, 2011, 01:58 PM
  3. Replies: 0
    Last Post: January 22nd, 2011, 11:52 AM
  4. client server communication
    By Brt93yoda in forum Java Theory & Questions
    Replies: 4
    Last Post: September 2nd, 2010, 04:49 PM
  5. [SOLVED] client-server-router problem
    By KrisTheSavage in forum Java Networking
    Replies: 2
    Last Post: August 23rd, 2010, 05:49 AM