Java 如何在android中使用fifo算法发送数据?
我正在尝试在android中实现FIFO算法。 所以我想做的是: 使用FIFO算法,一次发送一个方向。如何在这种情况下使用fifo。以时间间隔将这些方向直接发送到其他设备。我用的是安卓Java 如何在android中使用fifo算法发送数据?,java,android,algorithm,Java,Android,Algorithm,我正在尝试在android中实现FIFO算法。 所以我想做的是: 使用FIFO算法,一次发送一个方向。如何在这种情况下使用fifo。以时间间隔将这些方向直接发送到其他设备。我用的是安卓 //This is a function private void sendData(String message) { byte[] msgBuffer = message.getBytes(); Log.d(TAG, "...Send data: "
//This is a function
private void sendData(String message) {
byte[] msgBuffer = message.getBytes();
Log.d(TAG, "...Send data: " + message + "...");
try {
outStream.write(msgBuffer);
} catch (IOException e) {
String msg = "In onResume() and an exception occurred during write: " + e.getMessage();
if (address.equals("00:00:00:00:00:00"))
msg = msg + ".\n\nUpdate your server address from 00:00:00:00:00:00 to the correct address on line 35 in the java code";
msg = msg + ".\n\nCheck that the SPP UUID: " + MY_UUID.toString() + " exists on server.\n\n";
errorExit("Fatal Error", msg);
}
}
//this filter directions
while (!(node.parent == null)) {
//DIRECTIONS: L - Left, R - Right, U - up, D - Down
int nextX, nextY;
String direction = "";
nextX = node.parent.x;
nextY = node.parent.y;
if(nextX == node.x){
if(nextY > node.y){
direction = "S";
}else{
direction = "N";
sendData("n");
}
}
if(nextY == node.y){
if(nextX > node.x){
direction = "E";
sendData("e");
}
else{
direction = "W";
sendData("w");
}
}
if(nextY != node.y){
if(nextX < node.x){
direction = "NW";
sendData("7");
}else{
direction = "NE";
sendData("6");
}
}
Toast.makeText(getApplicationContext(), String.valueOf(direction), Toast.LENGTH_SHORT).show();
node = node.parent;
}
}
//这是一个函数
私有void sendData(字符串消息){
字节[]msgBuffer=message.getBytes();
Log.d(标记“…发送数据:“+消息+”);
试一试{
超流写入(msgBuffer);
}捕获(IOE异常){
字符串msg=“In onResume(),写入期间发生异常:“+e.getMessage();
如果(地址等于(“00:00:00:00:00”))
msg=msg+“\n\n将服务器地址从00:00:00:00:00更新到java代码第35行的正确地址”;
msg=msg+”\n\n检查SPP UUID:“+MY_UUID.toString()+”是否存在于服务器上。\n\n”;
errorExit(“致命错误”,msg);
}
}
//此过滤器用于指示方向
而(!(node.parent==null)){
//方向:左-左,右-右,U-上,D-下
int nextX,nextY;
字符串方向=”;
nextX=node.parent.x;
nextY=node.parent.y;
if(nextX==node.x){
if(nextY>node.y){
direction=“S”;
}否则{
方向=“N”;
sendData(“n”);
}
}
if(nextY==node.y){
如果(nextX>node.x){
方向=“E”;
sendData(“e”);
}
否则{
方向=“W”;
sendData(“w”);
}
}
if(nextY!=node.y){
if(nextX
如果只有一个套接字打开,则发送数据的默认值为FIFO btw,因此我不需要创建任何FIFO来发送数据?