嗨,我是编程新手
我想将温度实时值从服务器移动设备传输到客户端移动设备 通过套接字通过WIFI(本地网络)进行本地访问
private StringBuilder msg = new StringBuilder(2048);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mgr = (SensorManager) this.getSystemService(SENSOR_SERVICE);
if (mgr != null) {
temp = mgr.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);
}
Temptext = (TextView) findViewById(R.id.text);
}
@Override
protected void onResume() {
mgr.registerListener(this, temp, SensorManager.SENSOR_DELAY_NORMAL);
super.onResume();
}
@Override
protected void onPause() {
mgr.unregisterListener(this, temp);
super.onPause();
}
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
public void onSensorChanged(SensorEvent event) {
float fahrenheit = event.values[0] * 9 / 5 + 32;
msg.insert(0, "Got a sensor event: " + event.values[0] + " Celsius (" +
fahrenheit + " F)\n");
Temptext.setText(msg);
Temptext.invalidate();
}
}
但不知道如何流式传输 任何建议plz库等