Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to send message from PC and mobilephone using socket communication
    text
    copied!<p>this is my task:to connect PC and mobile phone using socket communication.i have a problem in sending the message i type in the socket connection. i use eclipse to run the program from PC to phone. i type in my text on the textbox. when i press the send button, i could not send the text and let it reflect on the phone. the program codes do not have errors anymore. this is the link i got for the codes: <a href="http://android-er.blogspot.sg/2011/01/simple-communication-using.html" rel="nofollow">http://android-er.blogspot.sg/2011/01/simple-communication-using.html</a></p> <p>these are my codes with no errors: </p> <pre><code>public class AndroidClient extends Activity { EditText textOut; TextView textIn; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.socket_client); textOut = (EditText)findViewById(R.id.textout); Button buttonSend = (Button)findViewById(R.id.send); textIn = (TextView)findViewById(R.id.textin); buttonSend.setOnClickListener(buttonSendOnClickListener); } Button.OnClickListener buttonSendOnClickListener = new Button.OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub Socket socket = null; DataOutputStream dataOutputStream = null; DataInputStream dataInputStream = null; try { socket = new Socket("10.217.137.207", 8888); dataOutputStream = new DataOutputStream(socket.getOutputStream()); dataInputStream = new DataInputStream(socket.getInputStream()); dataOutputStream.writeUTF(textOut.getText().toString()); textIn.setText(dataInputStream.readUTF()); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ if (socket != null){ try { socket.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (dataOutputStream != null){ try { dataOutputStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (dataInputStream != null){ try { dataInputStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }}; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload