English 中文(简体)
客户 Socket sediments SocketException:
原标题:Android client Socket throws SocketException:
  • 时间:2011-11-11 19:49:10
  •  标签:
  • java
  • android

我正试图将java的袖珍客户安装在roid,我的服务器是我的手提电脑。 我想我和roid的机动车用java的袖珍连接手提电脑。 但是,在客户方面,我却感到有例外:“欢迎”,而我看上去是因为呼吁书状无法适当编造。 下面是供审查的我的和roid客户旁码。 是否解决了这一例外情况:

public class SimpleActivityExampleActivity extends Activity  {

/** Called when the activity is first created. */
private String usrName;
private String vendorName;
private String message;
public Socket socket;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
  }


public void submitTheForm(View view) {

    final EditText edittext1 = (EditText) findViewById(R.id.editText1);
    final EditText edittext2 = (EditText) findViewById(R.id.EditText01);
    final EditText edittext3 = (EditText) findViewById(R.id.editText2);
    usrName = edittext1.getText().toString(); 
    vendorName = edittext2.getText().toString();
    message = edittext3.getText().toString();
    message = usrName+ "," + vendorName + "," + message;

    byte[] msg = message.getBytes();
    try {
    InetAddress serverAddr = InetAddress.getByName("192.168.1.2");
        Log.d("ClientActivity", "C: Connecting...");

        socket = new Socket(serverAddr, 2200);
    socket.getOutputStream().write(msg);
    socket.getOutputStream().flush();
    } catch (UnknownHostException e) {

        Toast.makeText(SimpleActivityExampleActivity.this, "unknownhostException", Toast.LENGTH_SHORT).show();
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SocketException e) {
        // TODO Auto-generated catch block

        Toast.makeText(SimpleActivityExampleActivity.this, "Sockexception", Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }catch (IOException e) {
        // TODO Auto-generated catch block
        //System.out.println("in IOexception for sure");
        Toast.makeText(SimpleActivityExampleActivity.this, "IOexception", Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }
    catch (Exception e){
        Toast.makeText(SimpleActivityExampleActivity.this, "Exception", Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }finally {
        if(socket != null){
            try {
                socket.close();

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
} 

提交 TheForm () function isquot on a button Point from main.xml file “android:onClick = “submitTheForm”

最佳回答

<uses-permission android:name="android.permission.INTERNET" />

许可?

创立:

问题回答

您是否可想把互联网许可添加到您的档案中?

<uses-permission android:name="android.permission.INTERNET" />




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签