我正在为学校开发一个Adroid应用程序,它是一个Android应用程序,可以将String(b)发送到服务器。没有Android的程序工作正常,我的问题是客户端类不能与android一起工作。
我的想法是,如果按下了按钮enterMessage,静态字符串b将被“enter”覆盖。之后,类客户端将启动并将字符串b发送到服务器。
主要类别:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public static void main(String[] args) {
}
public void enterMessage(View view) {
// Do something in response to button click
VarCheck.enter();
}
}
类Client;
public class Client {
public static void main() {
Send(null);
}
public static void Send(String b){
try {
Socket client = new Socket("localhost", 5556);
Log.d("DEBUG", "Client started");
OutputStream out = client.getOutputStream();
PrintWriter writer = new PrintWriter(out);
InputStream in = client.getInputStream();
BufferedReader reader = new BufferedReader(
new InputStreamReader(in));
writer.write(VarCheck.b + "\n");
writer.flush();
writer.close();
reader.close();
} catch (IOException e) {
}
}
}
Class VarCheck:
public class VarCheck extends Client{
public static String b = null;
public static void enter() {
b = "enter";
Client c1 = new Client();
Client.Send(b);
}
}
感谢您的帮助,对不起我糟糕的英语。 ;)