Network, the emulator can be connected, real machine can not connect.

  Abstract: network, the emulator can be connected, the real machine can not connect. 


  Is a simple procedure, the client and server simple dialogue. 

  Client updates, "this is client", and then revealed that information to the server. 
  Received news server, and then returned to "this is server"; 

  Simulator can run, not really connected to the machine. 
  J300, and internet access. 

  Client code 
  DataOutputStream dos = null; 
  DataInputStream dis = null; 
  Boolean berror = false; 
  Try ( 
  ServerHc = (HttpConnection) Connector.open ( "http://zengcity.vicp.net:8080/WMLParserWebModule/parserserver" 
Connector.READ_WRITE);
  ServerHc.setRequestMethod (HttpConnection.POST); 
  ServerHc.setRequestProperty ( "Connection", "Keep-Alive"); 
  ServerHc.setRequestProperty ( "Content-Type." 
  "Application / octet-stream"); 
  Berror = false; 

  ) Catch (IOException ex) ( 
  Berror = true; 
  ) 

  If (! Berror) ( 
  Try ( 
  ServerHc.openDataOutputStream dos = (); 
  Dos.writeUTF ( "Hello, this is client"); 
  ) Catch (IOException ex1) ( 
  Berror = true; 
  MainMIDlet.instance.displayable.tf_stat.setString ( "send error"); 
  ) 
  ) 

  If (! Berror) ( 
  Try ( 
  ServerHc.openDataInputStream dis = (); 
  MainMIDlet.instance.displayable.tf_stat.setString (dis.readUTF ()); 
  ) Catch (IOException ex2) ( 
  Berror = true; 
  MainMIDlet.instance.displayable.tf_stat.setString ( "receive error"); 
  ) 
  ) 

  Try ( 
  If (dos! = Null) ( 
  Dos.close (); 
  ) 
  If (dis! = Null) ( 
  Dis.close (); 
  ) 
  If (serverHc! = Null) ( 
  ServerHc.close (); 
  ) 
  ) Catch (IOException ex3) ( 
  ) 


  Server code: 

  Public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException ( 
  DataInputStream dis = new DataInputStream (request.getInputStream ()); 
  System.out.println (dis.readUTF ()); 

  DataOutputStream dos = new DataOutputStream (response.getOutputStream ()); 
  Dos.writeUTF ( "Hello, this is server"); 

  Dos.flush (); 
  Dos.close (); 
  Dis.close (); 
  ) 

  Where can the problem, please help me to see, thank you. 



  Proposed to do with a new thread 



  UP guitar scattered points in the paste.    .    . 



  Check the Client Server received the news?    Then should we judge 



  Send completed on the closure of re-opening reception! 


  ↑ Back 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags:

Releated Java Articles

Comments

Leave a Reply