0
我正在为学校开发一个Adroid应用程序,它是一个Android应用程序,可以将字符串(b)发送到服务器。没有Android的程序工作正常,我的问题是客户端类没有使用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();
}
}
类的客户端;
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);
}
}
感谢您的帮助,并抱歉,我的英语不好。 ;)
坦克你,这对我帮助很大,现在我的程序工作。 – Felix 2013-04-15 15:54:59