Client/Server ProgrammingHow does the socket API accept() function work?Java client socket returned by ServerSocket.accept()Java TCP Client Server working over LAN with port Forwarding but not with hamachiWhen there is a persistent connection how does a server identify subsequent request?I am confused about tcp demultiplexing?Java - Is it possible to send a client to another server?limit certain number of clients to connect to serverCannot communicate once bufferedwriter is close in java socket programmingJava TCP Hole PunchingServerSockets connecting to client

A PEMDAS issue request for explanation

2 load centers under 1 meter: do you need bonding and main breakers at both?

How would two worlds first establish an exchange rate between their currencies

Problem with listing a directory to grep

Why is the the worst case for this function O(n*n)

The meaning of "offing" in "an agreement in the offing"

Walking on an infinite grid

Contour plot of a sequence of spheres with increasing radius

Is future tense in English really a myth?

Strategies for dealing with chess burnout?

How should Thaumaturgy's "three times as loud as normal" be interpreted?

Distinguishing between octahedral and tetrahedral holes

Is there a "right" way to interpret a novel, if not, how do we make sure our novel is interpreted correctly?

Why would an AC motor heavily shake when driven with certain frequencies?

Why do the British opposition parties not want a new election?

How can I finish my PhD?

LGPL HDL in larger FPGA design

How invisible hand adjusts stock prices if company is listed on multiple exchanges, under multiple currencies, and one of the currencies plunges?

RANK used in 'where' returns invalid column, but exists in results set

Was Robin Hood's point of view ethically sound?

Short story: Interstellar inspector senses "off" nature of planet hiding aggressive culture

Stack class in Java8

Why can linguists decide which use of language is correct and which is not?

How should we understand "unobscured by flying friends" in this context?



Client/Server Programming


How does the socket API accept() function work?Java client socket returned by ServerSocket.accept()Java TCP Client Server working over LAN with port Forwarding but not with hamachiWhen there is a persistent connection how does a server identify subsequent request?I am confused about tcp demultiplexing?Java - Is it possible to send a client to another server?limit certain number of clients to connect to serverCannot communicate once bufferedwriter is close in java socket programmingJava TCP Hole PunchingServerSockets connecting to client






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am practicing a simple java program where I am demonstrating simple client server interaction. The fist part of message from server gets transferred. Then program just continues to run and does not execute? Do we need to create a new socket for each individual traffic?



Server code



server = new ServerSocket(4587);
System.out.print("Starting the Server on port " + server.getLocalPort() + "n");
System.out.println("Waiting for client...");

Socket client = server.accept();
BufferedWriter br = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
BufferedReader br1 = new BufferedReader(new InputStreamReader(client.getInputStream()));
br.write("Hello, you are connected to Server. What is your name?");
br.write("n");
br.flush();



while((s=br1.readLine())!=null)



br.write("Thank you ");
br.newLine();
br.flush();
}


Client code



String stdin;
System.out.println("Attempting to connect to " + hostname + ":" + port);
client = new Socket("localhost", 4587);
System.out.println("Connection Established");

BufferedReader br = new BufferedReader(new InputStreamReader(client.getInputStream()));
while ((stdin = br.readLine()) != null)
System.out.println(stdin);


BufferedWriter br1 = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
br1.write("Mike");
br1.write("n");
br1.flush();

while ((stdin = br.readLine()) != null)
System.out.println(stdin);



Server Output



Starting the Server on port4587
Waiting for client....


Client Output



 Attempting to connect to :123
Connection Established
Hello you are connected to Server, What is ur name


If this could help..after this both loop










share|improve this question


























  • Why the down vote? He has shown effort.

    – bblincoe
    Jan 23 '14 at 13:26











  • Well, IMHO, the the problem is reported in a vague way, and there is no clear reference to the code.

    – Alexis Leclerc
    Jan 23 '14 at 13:33

















0















I am practicing a simple java program where I am demonstrating simple client server interaction. The fist part of message from server gets transferred. Then program just continues to run and does not execute? Do we need to create a new socket for each individual traffic?



Server code



server = new ServerSocket(4587);
System.out.print("Starting the Server on port " + server.getLocalPort() + "n");
System.out.println("Waiting for client...");

Socket client = server.accept();
BufferedWriter br = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
BufferedReader br1 = new BufferedReader(new InputStreamReader(client.getInputStream()));
br.write("Hello, you are connected to Server. What is your name?");
br.write("n");
br.flush();



while((s=br1.readLine())!=null)



br.write("Thank you ");
br.newLine();
br.flush();
}


Client code



String stdin;
System.out.println("Attempting to connect to " + hostname + ":" + port);
client = new Socket("localhost", 4587);
System.out.println("Connection Established");

BufferedReader br = new BufferedReader(new InputStreamReader(client.getInputStream()));
while ((stdin = br.readLine()) != null)
System.out.println(stdin);


BufferedWriter br1 = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
br1.write("Mike");
br1.write("n");
br1.flush();

while ((stdin = br.readLine()) != null)
System.out.println(stdin);



Server Output



Starting the Server on port4587
Waiting for client....


Client Output



 Attempting to connect to :123
Connection Established
Hello you are connected to Server, What is ur name


If this could help..after this both loop










share|improve this question


























  • Why the down vote? He has shown effort.

    – bblincoe
    Jan 23 '14 at 13:26











  • Well, IMHO, the the problem is reported in a vague way, and there is no clear reference to the code.

    – Alexis Leclerc
    Jan 23 '14 at 13:33













0












0








0








I am practicing a simple java program where I am demonstrating simple client server interaction. The fist part of message from server gets transferred. Then program just continues to run and does not execute? Do we need to create a new socket for each individual traffic?



Server code



server = new ServerSocket(4587);
System.out.print("Starting the Server on port " + server.getLocalPort() + "n");
System.out.println("Waiting for client...");

Socket client = server.accept();
BufferedWriter br = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
BufferedReader br1 = new BufferedReader(new InputStreamReader(client.getInputStream()));
br.write("Hello, you are connected to Server. What is your name?");
br.write("n");
br.flush();



while((s=br1.readLine())!=null)



br.write("Thank you ");
br.newLine();
br.flush();
}


Client code



String stdin;
System.out.println("Attempting to connect to " + hostname + ":" + port);
client = new Socket("localhost", 4587);
System.out.println("Connection Established");

BufferedReader br = new BufferedReader(new InputStreamReader(client.getInputStream()));
while ((stdin = br.readLine()) != null)
System.out.println(stdin);


BufferedWriter br1 = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
br1.write("Mike");
br1.write("n");
br1.flush();

while ((stdin = br.readLine()) != null)
System.out.println(stdin);



Server Output



Starting the Server on port4587
Waiting for client....


Client Output



 Attempting to connect to :123
Connection Established
Hello you are connected to Server, What is ur name


If this could help..after this both loop










share|improve this question
















I am practicing a simple java program where I am demonstrating simple client server interaction. The fist part of message from server gets transferred. Then program just continues to run and does not execute? Do we need to create a new socket for each individual traffic?



Server code



server = new ServerSocket(4587);
System.out.print("Starting the Server on port " + server.getLocalPort() + "n");
System.out.println("Waiting for client...");

Socket client = server.accept();
BufferedWriter br = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
BufferedReader br1 = new BufferedReader(new InputStreamReader(client.getInputStream()));
br.write("Hello, you are connected to Server. What is your name?");
br.write("n");
br.flush();



while((s=br1.readLine())!=null)



br.write("Thank you ");
br.newLine();
br.flush();
}


Client code



String stdin;
System.out.println("Attempting to connect to " + hostname + ":" + port);
client = new Socket("localhost", 4587);
System.out.println("Connection Established");

BufferedReader br = new BufferedReader(new InputStreamReader(client.getInputStream()));
while ((stdin = br.readLine()) != null)
System.out.println(stdin);


BufferedWriter br1 = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
br1.write("Mike");
br1.write("n");
br1.flush();

while ((stdin = br.readLine()) != null)
System.out.println(stdin);



Server Output



Starting the Server on port4587
Waiting for client....


Client Output



 Attempting to connect to :123
Connection Established
Hello you are connected to Server, What is ur name


If this could help..after this both loop







java sockets tcp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 24 '14 at 12:35







Koneri

















asked Jan 23 '14 at 13:14









KoneriKoneri

1821 gold badge9 silver badges25 bronze badges




1821 gold badge9 silver badges25 bronze badges















  • Why the down vote? He has shown effort.

    – bblincoe
    Jan 23 '14 at 13:26











  • Well, IMHO, the the problem is reported in a vague way, and there is no clear reference to the code.

    – Alexis Leclerc
    Jan 23 '14 at 13:33

















  • Why the down vote? He has shown effort.

    – bblincoe
    Jan 23 '14 at 13:26











  • Well, IMHO, the the problem is reported in a vague way, and there is no clear reference to the code.

    – Alexis Leclerc
    Jan 23 '14 at 13:33
















Why the down vote? He has shown effort.

– bblincoe
Jan 23 '14 at 13:26





Why the down vote? He has shown effort.

– bblincoe
Jan 23 '14 at 13:26













Well, IMHO, the the problem is reported in a vague way, and there is no clear reference to the code.

– Alexis Leclerc
Jan 23 '14 at 13:33





Well, IMHO, the the problem is reported in a vague way, and there is no clear reference to the code.

– Alexis Leclerc
Jan 23 '14 at 13:33












3 Answers
3






active

oldest

votes


















0
















Your server will first create a connection with the client through the accept method. If you wish to have multiple clients you will need to change your code accordingly to accept that.



On the client side, you're using n to delineate the end of a message. This will work fine. Every time you send a new message use n to indicate the end of the message.



On the server side, you should continue reading from I/O until you see the n. At that point you have received the entire message. Process it and than start listening again.



Edit:



Since you are waiting for the name of the client, you could simply do the following on the server:



BufferedWriter bout = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
BufferedReader bin = new BufferedReader(new InputStreamWriter(client.getInputStream()));
// Wait for incoming name from client.
String name = bin.readline();
System.out.println(name);
// Send a reply.
bout.write("Thank youn");
bout.flush();


Similarly, on the client (assuming bin and bout are defined the same as above):



// Send name to server.
bout.write("Namen");
bout.flush();
// Get a response from the server and print to console.
String response = bin.readline();
System.out.println(response);





share|improve this answer



























  • like should i use while loop while reading from client

    – Koneri
    Jan 24 '14 at 12:12











  • That would be acceptable - it really just depends on what you're trying to achieve. Inside your while loop you can read each message and process it. After your done you'll go back to reading the next line. You may want to consider listening forever (in a while(true) loop) on a separate thread to allow the server to do other things besides listening all the time.

    – bblincoe
    Jan 24 '14 at 12:31












  • I edited my server code. Could you please take a look at it

    – Koneri
    Jan 24 '14 at 12:34











  • @Koneri I've updated my answer. Hopefully it will get you started.

    – bblincoe
    Jan 24 '14 at 13:35











  • Fine this solves it thank you. And i had one question one connection is set up between client and server. Can we call the method of server and receive the response.

    – Koneri
    Jan 25 '14 at 8:06


















0
















This is because BufferedReader has a default buffer = 8K when in reading process and this process is block I/O, so this will hang in that point. You should read the full message from client by server side.






share|improve this answer
































    0
















    Your problem is with the loop on the client side. It will be stuck in the loop as it waits to readlines sent from the server infinitely. (ie, after reading the first line from the server, it will expect more lines from the server and wait to read them).



    To exit the loop you need to send an EOF signal or end of stream signal (according to the docs: http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html#readLine%28%29)






    share|improve this answer

























    • He's sending a n which is his indicator for EOF.

      – bblincoe
      Jan 24 '14 at 12:31













    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21309266%2fclient-server-programming%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0
















    Your server will first create a connection with the client through the accept method. If you wish to have multiple clients you will need to change your code accordingly to accept that.



    On the client side, you're using n to delineate the end of a message. This will work fine. Every time you send a new message use n to indicate the end of the message.



    On the server side, you should continue reading from I/O until you see the n. At that point you have received the entire message. Process it and than start listening again.



    Edit:



    Since you are waiting for the name of the client, you could simply do the following on the server:



    BufferedWriter bout = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
    BufferedReader bin = new BufferedReader(new InputStreamWriter(client.getInputStream()));
    // Wait for incoming name from client.
    String name = bin.readline();
    System.out.println(name);
    // Send a reply.
    bout.write("Thank youn");
    bout.flush();


    Similarly, on the client (assuming bin and bout are defined the same as above):



    // Send name to server.
    bout.write("Namen");
    bout.flush();
    // Get a response from the server and print to console.
    String response = bin.readline();
    System.out.println(response);





    share|improve this answer



























    • like should i use while loop while reading from client

      – Koneri
      Jan 24 '14 at 12:12











    • That would be acceptable - it really just depends on what you're trying to achieve. Inside your while loop you can read each message and process it. After your done you'll go back to reading the next line. You may want to consider listening forever (in a while(true) loop) on a separate thread to allow the server to do other things besides listening all the time.

      – bblincoe
      Jan 24 '14 at 12:31












    • I edited my server code. Could you please take a look at it

      – Koneri
      Jan 24 '14 at 12:34











    • @Koneri I've updated my answer. Hopefully it will get you started.

      – bblincoe
      Jan 24 '14 at 13:35











    • Fine this solves it thank you. And i had one question one connection is set up between client and server. Can we call the method of server and receive the response.

      – Koneri
      Jan 25 '14 at 8:06















    0
















    Your server will first create a connection with the client through the accept method. If you wish to have multiple clients you will need to change your code accordingly to accept that.



    On the client side, you're using n to delineate the end of a message. This will work fine. Every time you send a new message use n to indicate the end of the message.



    On the server side, you should continue reading from I/O until you see the n. At that point you have received the entire message. Process it and than start listening again.



    Edit:



    Since you are waiting for the name of the client, you could simply do the following on the server:



    BufferedWriter bout = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
    BufferedReader bin = new BufferedReader(new InputStreamWriter(client.getInputStream()));
    // Wait for incoming name from client.
    String name = bin.readline();
    System.out.println(name);
    // Send a reply.
    bout.write("Thank youn");
    bout.flush();


    Similarly, on the client (assuming bin and bout are defined the same as above):



    // Send name to server.
    bout.write("Namen");
    bout.flush();
    // Get a response from the server and print to console.
    String response = bin.readline();
    System.out.println(response);





    share|improve this answer



























    • like should i use while loop while reading from client

      – Koneri
      Jan 24 '14 at 12:12











    • That would be acceptable - it really just depends on what you're trying to achieve. Inside your while loop you can read each message and process it. After your done you'll go back to reading the next line. You may want to consider listening forever (in a while(true) loop) on a separate thread to allow the server to do other things besides listening all the time.

      – bblincoe
      Jan 24 '14 at 12:31












    • I edited my server code. Could you please take a look at it

      – Koneri
      Jan 24 '14 at 12:34











    • @Koneri I've updated my answer. Hopefully it will get you started.

      – bblincoe
      Jan 24 '14 at 13:35











    • Fine this solves it thank you. And i had one question one connection is set up between client and server. Can we call the method of server and receive the response.

      – Koneri
      Jan 25 '14 at 8:06













    0














    0










    0









    Your server will first create a connection with the client through the accept method. If you wish to have multiple clients you will need to change your code accordingly to accept that.



    On the client side, you're using n to delineate the end of a message. This will work fine. Every time you send a new message use n to indicate the end of the message.



    On the server side, you should continue reading from I/O until you see the n. At that point you have received the entire message. Process it and than start listening again.



    Edit:



    Since you are waiting for the name of the client, you could simply do the following on the server:



    BufferedWriter bout = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
    BufferedReader bin = new BufferedReader(new InputStreamWriter(client.getInputStream()));
    // Wait for incoming name from client.
    String name = bin.readline();
    System.out.println(name);
    // Send a reply.
    bout.write("Thank youn");
    bout.flush();


    Similarly, on the client (assuming bin and bout are defined the same as above):



    // Send name to server.
    bout.write("Namen");
    bout.flush();
    // Get a response from the server and print to console.
    String response = bin.readline();
    System.out.println(response);





    share|improve this answer















    Your server will first create a connection with the client through the accept method. If you wish to have multiple clients you will need to change your code accordingly to accept that.



    On the client side, you're using n to delineate the end of a message. This will work fine. Every time you send a new message use n to indicate the end of the message.



    On the server side, you should continue reading from I/O until you see the n. At that point you have received the entire message. Process it and than start listening again.



    Edit:



    Since you are waiting for the name of the client, you could simply do the following on the server:



    BufferedWriter bout = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
    BufferedReader bin = new BufferedReader(new InputStreamWriter(client.getInputStream()));
    // Wait for incoming name from client.
    String name = bin.readline();
    System.out.println(name);
    // Send a reply.
    bout.write("Thank youn");
    bout.flush();


    Similarly, on the client (assuming bin and bout are defined the same as above):



    // Send name to server.
    bout.write("Namen");
    bout.flush();
    // Get a response from the server and print to console.
    String response = bin.readline();
    System.out.println(response);






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 24 '14 at 13:34

























    answered Jan 23 '14 at 13:25









    bblincoebblincoe

    1,80316 silver badges29 bronze badges




    1,80316 silver badges29 bronze badges















    • like should i use while loop while reading from client

      – Koneri
      Jan 24 '14 at 12:12











    • That would be acceptable - it really just depends on what you're trying to achieve. Inside your while loop you can read each message and process it. After your done you'll go back to reading the next line. You may want to consider listening forever (in a while(true) loop) on a separate thread to allow the server to do other things besides listening all the time.

      – bblincoe
      Jan 24 '14 at 12:31












    • I edited my server code. Could you please take a look at it

      – Koneri
      Jan 24 '14 at 12:34











    • @Koneri I've updated my answer. Hopefully it will get you started.

      – bblincoe
      Jan 24 '14 at 13:35











    • Fine this solves it thank you. And i had one question one connection is set up between client and server. Can we call the method of server and receive the response.

      – Koneri
      Jan 25 '14 at 8:06

















    • like should i use while loop while reading from client

      – Koneri
      Jan 24 '14 at 12:12











    • That would be acceptable - it really just depends on what you're trying to achieve. Inside your while loop you can read each message and process it. After your done you'll go back to reading the next line. You may want to consider listening forever (in a while(true) loop) on a separate thread to allow the server to do other things besides listening all the time.

      – bblincoe
      Jan 24 '14 at 12:31












    • I edited my server code. Could you please take a look at it

      – Koneri
      Jan 24 '14 at 12:34











    • @Koneri I've updated my answer. Hopefully it will get you started.

      – bblincoe
      Jan 24 '14 at 13:35











    • Fine this solves it thank you. And i had one question one connection is set up between client and server. Can we call the method of server and receive the response.

      – Koneri
      Jan 25 '14 at 8:06
















    like should i use while loop while reading from client

    – Koneri
    Jan 24 '14 at 12:12





    like should i use while loop while reading from client

    – Koneri
    Jan 24 '14 at 12:12













    That would be acceptable - it really just depends on what you're trying to achieve. Inside your while loop you can read each message and process it. After your done you'll go back to reading the next line. You may want to consider listening forever (in a while(true) loop) on a separate thread to allow the server to do other things besides listening all the time.

    – bblincoe
    Jan 24 '14 at 12:31






    That would be acceptable - it really just depends on what you're trying to achieve. Inside your while loop you can read each message and process it. After your done you'll go back to reading the next line. You may want to consider listening forever (in a while(true) loop) on a separate thread to allow the server to do other things besides listening all the time.

    – bblincoe
    Jan 24 '14 at 12:31














    I edited my server code. Could you please take a look at it

    – Koneri
    Jan 24 '14 at 12:34





    I edited my server code. Could you please take a look at it

    – Koneri
    Jan 24 '14 at 12:34













    @Koneri I've updated my answer. Hopefully it will get you started.

    – bblincoe
    Jan 24 '14 at 13:35





    @Koneri I've updated my answer. Hopefully it will get you started.

    – bblincoe
    Jan 24 '14 at 13:35













    Fine this solves it thank you. And i had one question one connection is set up between client and server. Can we call the method of server and receive the response.

    – Koneri
    Jan 25 '14 at 8:06





    Fine this solves it thank you. And i had one question one connection is set up between client and server. Can we call the method of server and receive the response.

    – Koneri
    Jan 25 '14 at 8:06













    0
















    This is because BufferedReader has a default buffer = 8K when in reading process and this process is block I/O, so this will hang in that point. You should read the full message from client by server side.






    share|improve this answer





























      0
















      This is because BufferedReader has a default buffer = 8K when in reading process and this process is block I/O, so this will hang in that point. You should read the full message from client by server side.






      share|improve this answer



























        0














        0










        0









        This is because BufferedReader has a default buffer = 8K when in reading process and this process is block I/O, so this will hang in that point. You should read the full message from client by server side.






        share|improve this answer













        This is because BufferedReader has a default buffer = 8K when in reading process and this process is block I/O, so this will hang in that point. You should read the full message from client by server side.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 23 '14 at 13:26









        richierichie

        1793 bronze badges




        1793 bronze badges
























            0
















            Your problem is with the loop on the client side. It will be stuck in the loop as it waits to readlines sent from the server infinitely. (ie, after reading the first line from the server, it will expect more lines from the server and wait to read them).



            To exit the loop you need to send an EOF signal or end of stream signal (according to the docs: http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html#readLine%28%29)






            share|improve this answer

























            • He's sending a n which is his indicator for EOF.

              – bblincoe
              Jan 24 '14 at 12:31















            0
















            Your problem is with the loop on the client side. It will be stuck in the loop as it waits to readlines sent from the server infinitely. (ie, after reading the first line from the server, it will expect more lines from the server and wait to read them).



            To exit the loop you need to send an EOF signal or end of stream signal (according to the docs: http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html#readLine%28%29)






            share|improve this answer

























            • He's sending a n which is his indicator for EOF.

              – bblincoe
              Jan 24 '14 at 12:31













            0














            0










            0









            Your problem is with the loop on the client side. It will be stuck in the loop as it waits to readlines sent from the server infinitely. (ie, after reading the first line from the server, it will expect more lines from the server and wait to read them).



            To exit the loop you need to send an EOF signal or end of stream signal (according to the docs: http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html#readLine%28%29)






            share|improve this answer













            Your problem is with the loop on the client side. It will be stuck in the loop as it waits to readlines sent from the server infinitely. (ie, after reading the first line from the server, it will expect more lines from the server and wait to read them).



            To exit the loop you need to send an EOF signal or end of stream signal (according to the docs: http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html#readLine%28%29)







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 23 '14 at 13:40









            diddlesdiddles

            1046 bronze badges




            1046 bronze badges















            • He's sending a n which is his indicator for EOF.

              – bblincoe
              Jan 24 '14 at 12:31

















            • He's sending a n which is his indicator for EOF.

              – bblincoe
              Jan 24 '14 at 12:31
















            He's sending a n which is his indicator for EOF.

            – bblincoe
            Jan 24 '14 at 12:31





            He's sending a n which is his indicator for EOF.

            – bblincoe
            Jan 24 '14 at 12:31


















            draft saved

            draft discarded















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21309266%2fclient-server-programming%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript