【发布时间】:2018-01-23 11:37:09
【问题描述】:
我有一个应用程序通过套接字在本地网络上与其他设备进行通信。在那我还想传输文件和文本。 我的问题是我不知道如何获取文件和文本并在接收中管理它们!
这是我的文本接收器:
try {
outputStream = new DataOutputStream(socket.getOutputStream());
outputstream_external = outputStream;
inputStream = new BufferedReader(new InputStreamReader(socket.getInputStream()));
log("success to set streams");
}
catch (IOException e1) {
log("Error: Connection is not stable, exit");
shutdown();
}
while (true) {
String message = null;
try {
message = inputStream.readLine();
if (message == null) {
return;
}
G.log(message);
JSONObject object = new JSONObject(message);
String command = object.getString(Command.COMMAND);
G.log(message);
这是我的短信发件人:
public void sendCommand(String command) {
G.log("send command + " + command);
command = command.replace("\n", " ") + "\n";
if (outputStream == null) {
return;
}
final String commend = command;
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
outputStream.write(commend.getBytes());
}
catch (IOException e) {
e.printStackTrace();
G.log("sendCommand into catch");
}
}
});
thread.start();
}
如何同时接收文本和文件?
【问题讨论】: