for an mmo  I am attempting to create, I have an android client connecting 
to a java server. The android is running on the emulator while the server 
is running straight on my computer. They can connect fine and acknowledge 
the connection but  unless I close either the client or the server the 
other can't recieve the former's message but they can if I do close one.

The server's WorkerThread's Run method:
[code]
        
    public void run() {
        try {
            InputStream input  = clientSocket.getInputStream();
            OutputStream output = clientSocket.getOutputStream();
            String returns="";
            String s="";
            try{
            s= inputStreamToString(input).toString();
            }
            catch(Exception e)
            {}
           output.write(("HTTP/1.1 200 OK\n\nWorkerRunnable: " +
                   this.serverText + " - " +
                   "").getBytes());
            output.close();
            input.close();
        } catch (IOException e) {
            //report exception somewhere.
            e.printStackTrace();
        }
    }[/code]

The InputStream stringbulider:
[code]
private static StringBuilder inputStreamToString(InputStream is) {
String line = "";
StringBuilder total = new StringBuilder();

BufferedReader rd = new BufferedReader(new InputStreamReader(is));

try {
while ((line = rd.readLine()) != null) {
total.append(line);
}
} catch (Exception e) {
}

return total;}
[/code]

The client's connection method:

[code]      public String sendMessage(String message)
      {
    try{ clientSocket = new Socket("10.0.2.2", 9000);
    
      String modifiedSentence;
      DataOutputStream outToServer = new 
DataOutputStream(clientSocket.getOutputStream());
      BufferedReader inFromServer = new BufferedReader(new 
InputStreamReader(clientSocket.getInputStream()));
      outToServer.writeBytes(message+"\n");
                  //Stops here
      modifiedSentence = inFromServer.readLine();
      outToServer.close();
      inFromServer.close();
      clientSocket.close();
      Log.v(modifiedSentence, modifiedSentence);
      return modifiedSentence;}
    catch(Exception e)
    {
    return "";}
     
      }[/code]

Thanks, any help will be appreciated.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to