This is my first question. I was looking for solutions to such problems, but in each case there were some differences compared to my case. I am trying to establish a simple connection between a Python server and an Android application using sockets. The Android application starts a conversation with the server: it sends a message to the server, the server receives and displays it, and then the server sends a response to the application. The application displays the response on the screen in TextView. This is my client side code:
public class MyClient extends Activity implements OnClickListener{ EditText enterMessage; Button sendbutton; @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.myclient); enterMessage = (EditText)findViewById(R.id.enterMessage); sendbutton = (Button)findViewById(R.id.sendbutton); sendbutton.setOnClickListener(this); } @Override public void onClick(View arg0) { Thread t = new Thread(){ @Override public void run() { try { Socket s = new Socket("192.168.183.1", 7000); DataOutputStream dos = new DataOutputStream(s.getOutputStream()); dos.writeUTF(enterMessage.getText().toString());
And on the server side, this is my code:
from socket import * HOST = "192.168.183.1"
When I try to send a message from the application to the server, it works fine. However, as soon as the server receives the message and displays it, the application immediately stops with the error message: it unexpectedly stopped. Please try again. Additional info: I use adt-bundle for Android development and IDLE for running server code. Both on Windows8.
source share