0
나는 안드로이드 응용 프로그램 인 학교용 Adroid 응용 프로그램을 개발 중이며이 응용 프로그램은 String (b)을 서버에 보낼 수 있습니다. 안드로이드없는 programm 잘하고 내 문제는 클라이언트 클래스 안드로이드와 함께 작동하지 않습니다.안드로이드 클라이언트 및 서버 통신 문제
내 생각에 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 VarCheck extends Client{
public static String b = null;
public static void enter() {
b = "enter";
Client c1 = new Client();
Client.Send(b);
}
}
감사합니다, 미안 :
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
. ;)
탱크를. – Felix