📄 asciiwriter.java
字号:
/* -*- indent-tabs-mode:T; c-basic-offset:8; tab-width:8; -*- vi: set ts=8:
* $Id: ASCIIWriter.java,v 1.1 2002/07/14 04:31:52 dennisda Exp $
*
* (c) Dennis D'Annunzio <ciogeneral@positivechanges.com>
*
*************
*
* This file is part of the autopilot simulation package.
* http://autopilot.sf.net
*
* Autopilot is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Autopilot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Autopilot; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package net.sf.autopilot.downlink.uav;
import java.net.ServerSocket;
import java.io.IOException;
import java.io.DataInputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.io.ObjectOutputStream;
import java.io.BufferedOutputStream;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.DatagramPacket;
/* Generated by Together */
public class ASCIIWriter extends Thread {
ServerSocket serverSocket;
int threadNumber;
TelemetryServer systemHandle;
boolean active;
PrintStream os;
DatagramSocket dgSocket;
InetAddress inetAddr;
InetAddress group;
// prob should use obj oriented techniques to implement socket types
public TelemetryServer getSystemHandle() { return systemHandle; }
ASCIIWriter(TelemetryServer systemHandle, ServerSocket s, int i) {
super();
serverSocket = s;
threadNumber = i;
this.systemHandle = systemHandle;
setName("SH_TH:" + threadNumber);
active = false;
}
public void run() {
Socket clientSocket = null;
while (true) {
try {
System.out.println(getName() + " waiting"); // debug output
clientSocket = null;
synchronized(serverSocket) {
clientSocket = serverSocket.accept();
}
clientSocket.setSendBufferSize(512);
clientSocket.setTcpNoDelay(true);
active = true;
inetAddr = clientSocket.getInetAddress();
System.out.println(getName() + " starting, IP=" + inetAddr);
System.out.flush();
DataInputStream is = new DataInputStream(clientSocket.getInputStream());
os = null;
os = new PrintStream(clientSocket.getOutputStream(), true);
String line;
while ((line = is.readLine()) != null) {
// do nothing on input yet
}
clientSocket.close();
os.close();
active = false;
} catch (IOException ex) {
System.out.println(getName() + ": IO Error on socket " + ex); // error output
try {
clientSocket.close();
os.close();
} catch (Exception ge) {
System.out.println(getName() + ": Unable to close network resources");
}
} finally {
active = false;
}
}
}
synchronized public void sendLine(String line) {
try {
if (null == line) {
//
} else {
try {
os.print(line + "\r\n");
os.flush();
} catch (Exception e) {
System.out.println("ERROR: sendLine() os.print(), " + e);
System.out.flush();
}
}
} catch (Exception e) {
System.out.println("ERROR: sendLine() main clause exception, " + e);
System.out.flush();
}
}
public boolean isActive() { return active; }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -