繁体   English   中英

Android客户端和服务器通讯问题

[英]Android Client and Server communication issue

我正在为学校开发一个Adroid应用程序,它是一个Android应用程序,可以将字符串(b)发送到服务器。 没有Android的程序运行正常,我的问题是客户端类无法与android一起使用。

我的想法是,如果按下Button enterMessage,则静态字符串b将被“ enter”覆盖。 之后,Class Client将启动并将String 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) {

        }
    }
}

类VarCheck:

public class VarCheck extends Client{

public static String b = null;

public static void enter() {
    b = "enter";
    Client c1 = new Client();
    Client.Send(b);
    }
}

感谢您的帮助,对不起我的英语不好。 ;)

希望这个能对您有所帮助 ..

Android服务器客户端

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM