Getting remote device file list via BT in Java/Android - java

I'm trying to get the remote device folder listing using OBEX; i'm trying to connect using
String btUrl=btgoep://"+mac_address+":10;authenticate=false;encrypt=false;master=false"
but i get Not supported yet error when i call
ClientSession conn = (ClientSession) Connector.open(btURL);
Can anyone help me?

The port may be incorrect. You should get connection addres via service search in DiscoveryListener. In jsr82 it looks like this:
private final UUID L2CAP_UUID = new UUID(0x1106);
public String getOBEXURL(RemoteDevice dev) {
DiscoveryAgent discoveryAgent = null;
try {
LocalDevice localDevice = LocalDevice.getLocalDevice();
discoveryAgent = localDevice.getDiscoveryAgent();
}
catch (Exception e) {
return null;
}
try {
discoveryAgent.searchServices(null, new UUID[]{L2CAP_UUID}, dev, this);
} catch (Exception e) {
return null;
}
synchronized (this) {
try { wait(); }
catch (Exception e) {}
}
switch (respCode) {
case SERVICE_SEARCH_DEVICE_NOT_REACHABLE:
ps.println("Remote device could not be reached");
break;
case SERVICE_SEARCH_ERROR:
ps.println("The service search was terminated with error");
break;
case SERVICE_SEARCH_NO_RECORDS:
ps.println("No services found on device");
break;
case SERVICE_SEARCH_TERMINATED:
ps.println("The service search has been canceled by the application and did not complete");
break;
}
return obexURL;
}
public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
obexURL = servRecord[0].getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
}
public void serviceSearchCompleted(int transID, int respCode) {
this.respCode = respCode;
synchronized (this) { notify(); }
}

Try this.
private void GetFileNamesViaBTFTP(UUID UUID3)
{
try
{
mBtSocket = mBtDevice.createInsecureRfcommSocketToServiceRecord(UUID3);
}
catch (Exception e)
{
//e.printStackTrace();
}
Thread thread=new Thread(new Runnable() {
public void run()
{
UUID uuid=UUID.fromString("F9EC7BC4-953C-11D2-984E-525400DC9E09");
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
bb.putLong(uuid.getMostSignificantBits());
bb.putLong(uuid.getLeastSignificantBits());
byte [] bytes=bb.array();
Operation putOperation=null;
Operation getOperation=null;
//ArrayUtils.reverse(bytes);
try
{
// 소켓을 연결한다
mBtSocket.connect();
mSession = new ClientSession((ObexTransport)(mTransport = new BluetoothObexTransport(mBtSocket)));
HeaderSet headerset = new HeaderSet();
headerset.setHeader(HeaderSet.TARGET, bytes);
headerset = mSession.connect(headerset);
if (headerset.getResponseCode() == ResponseCodes.OBEX_HTTP_OK)
{
mConnected = true;
}
else
{
mSession.disconnect(headerset);
}
// Send a file with meta data to the server
final byte filebytes[] = "[CLIENT] Hello..".getBytes();
final HeaderSet hs = new HeaderSet();
hs.setHeader(HeaderSet.NAME, "test.txt");
hs.setHeader(HeaderSet.TYPE, "text/plain");
hs.setHeader(HeaderSet.LENGTH, new Long((long)filebytes.length));
putOperation = mSession.put(hs);
mOutput = putOperation.openOutputStream();
mOutput.write(filebytes);
mOutput.close();
putOperation.close();
//In order to go the desired folder the OBEX SETPATH command is
//being used
//Prepare the header for the SETPATH command
HeaderSet header = new HeaderSet();
//folder_name is set to the name of the desired folder
//if left blank the root folder will be used
//header.setHeader(HeaderSet.NAME, "");
//Send the SETPATH command
/*result =*/ mSession.setPath(header, false, false);
final HeaderSet geths = new HeaderSet();
//geths.setHeader(HeaderSet.NAME, null);
geths.setHeader(HeaderSet.TYPE, "x-obex/folder-listing");
//hs.setHeader(HeaderSet.LENGTH, new Long((long)filebytes.length));
getOperation = mSession.get(geths);
InputStreamReader din = new
InputStreamReader(getOperation.openInputStream(), "UTF-8");
BufferedReader bufferedReader = new BufferedReader(din);
String tmp2=new String();
String line = bufferedReader.readLine();
while (line != null)
{
tmp2 += line;//System.out.println(line);
line = bufferedReader.readLine();
}
bufferedReader.close();
getOperation.close();
/*
mInput=getOperation.openInputStream();
// Retrieve the length of the object being sent back
int length = (int) getOperation.getLength();
// Create space for the object
byte[] obj = new byte[length];
// Get the object from the input stream
DataInputStream in = getOperation.openDataInputStream();
in.read(obj);
// End the transaction
in.close();
*/
final String ftmp=tmp2;
runOnUiThread(new Runnable(){
#Override
public void run()
{
//String s=new String(ftmp, "UTF-16");
deviceTextEdit.setText(ftmp);
}
});
Xml xml;
}
catch (Exception e)
{
//e.printStackTrace();
}
finally
{
try
{
mOutput.close();
putOperation.close();
mSession.disconnect(null);
}
catch (IOException e)
{}
//updateStatus("[CLIENT] Connection Closed");
}
}
});
thread.start();
}
Now your work is to parse XML data of obexfolder listing.

Related

java.net.SocketException: Broken pipe (Please give me design advice.)

public class NewsServer {
Socket socket;
ArticleData ad;
DataType dt;
boolean isRecv = false;
DataOutputStream dos;
private static final int THREAD_CNT = 5;
private static ExecutorService threadPool = Executors.newFixedThreadPool(THREAD_CNT, new ThreadFactory() {
#Override
public Thread newThread(Runnable r) {
Thread t = Executors.defaultThreadFactory().newThread(r);
t.setDaemon(true);
return t;
}
});
private static ExecutorService pollThreadPool = Executors.newSingleThreadExecutor();
public NewsServer() {
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(7777);
while (true) {
socket = serverSocket.accept();
try {
threadPool.execute(new WriteThread(socket));
pollThreadPool.execute(new PollingThread(socket));
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (IOException e) {
try {
serverSocket.close();
} catch (IOException e1) {
e1.printStackTrace();
}
e.printStackTrace();
}
}
// polling
class PollingThread implements Runnable {
private Socket tsocket;
public PollingThread(Socket socket) {
this.tsocket = socket;
}
#Override
public void run() {
try {
DataOutputStream dos = new DataOutputStream(tsocket.getOutputStream());
ArticleData ads = new ArticleData(dos);
while (!tsocket.isClosed()) {
ads.sendPolling();
Thread.sleep(Constant.POLLING_INTERVAL);
}
} catch (SocketException e) {
try {
tsocket.close();
} catch (IOException ie) {
ie.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
try {
tsocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
// send news
class WriteThread implements Runnable {
private Socket tsocket = null;
private boolean readySend = true;
private boolean doSend = true;
public WriteThread(Socket socket) {
this.tsocket = socket;
}
#Override
public void run() {
int dataTypeDiv = 0;
try {
DataOutputStream dos = new DataOutputStream(tsocket.getOutputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(tsocket.getInputStream()));
NewsDataFile newsDataFile = null;
StringBuffer bodyBuffer = new StringBuffer();
while (true) {
if (doSend) {
newsDataFile = sendNewsData(dos);
doSend = false;
}
try {
int readByteCount = br.read();
if (readByteCount == DataType.STX) {
doSend = false;
} else if (readByteCount == DataType.ETX) {
if (dataTypeDiv == DataType.ACK) {
doSend = true;
if (newsDataFile != null) {
newsDataFile.removeNewsData();
}
} else if (dataTypeDiv == DataType.NAK) {
doSend = true;
}
} else if (readByteCount == DataType.ACK) {
dataTypeDiv = readByteCount;
} else if (readByteCount == DataType.NAK) {
dataTypeDiv = readByteCount;
} else {
bodyBuffer.append(readByteCount);
doSend = false;
}
} catch (IOException e) {
readySend = true;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
tsocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* #param dos
* #throws Exception
* #throws ParseException
* #throws IOException
*/
private NewsDataFile sendNewsData(DataOutputStream dos) throws Exception, ParseException, IOException {
String jsonNewsData = null;
NewsDataFile newsDataFile = new NewsDataFile();
while (true) {
jsonNewsData = newsDataFile.getJsonNewsData();
if (jsonNewsData != null) {
JSONParser jsonParse = new JSONParser();
JSONObject articleObject = (JSONObject) jsonParse.parse(jsonNewsData);
String status = (String) articleObject.get("status");
String sn = (String) articleObject.get("sn");
String code = (String) articleObject.get("code");
String wdate = (String) articleObject.get("wdate");
String sdate = (String) articleObject.get("sdate");
String cate = (String) articleObject.get("cate");
String title = (String) articleObject.get("title");
String reporter = (String) articleObject.get("reporter");
String stockcd1 = (String) articleObject.get("stockcd1");
String stockcd2 = (String) articleObject.get("stockcd2");
String stockcd3 = (String) articleObject.get("stockcd3");
String stockcd4 = (String) articleObject.get("stockcd4");
String stockcd5 = (String) articleObject.get("stockcd5");
String stockcd6 = (String) articleObject.get("stockcd6");
String stockcd7 = (String) articleObject.get("stockcd7");
String stockcd8 = (String) articleObject.get("stockcd8");
String prepare1 = (String) articleObject.get("prepare1");
String prepare2 = (String) articleObject.get("prepare2");
String body = (String) articleObject.get("body");
ArticleData articleData = new ArticleData(dos);
articleData.setArticle(status, sn, code, wdate, sdate, cate, title, reporter, stockcd1, stockcd2,
stockcd3, stockcd4, stockcd5, stockcd6, stockcd7, stockcd8, prepare1, prepare2, body);
articleData.writeDataExternal();
dos.flush();
articleData = null;
articleObject = null;
jsonParse = null;
break;
}
}
return newsDataFile;
}
}
public static final byte[] getbytes(byte src[], int offset, int length) {
byte dest[] = new byte[length];
System.arraycopy(src, offset, dest, 0, length);
return dest;
}
public static void main(String[] args) {
new NewsServer();
}
}
When a client connects, the news server sends polling every 30 seconds to maintain the connection.
When a news file is created, the news content is converted into byte and transmitted to the waiting client.
I implemented it as described above, but the connection is frequently lost.
If you have any design problems or have any advice, please let me know. I'm embarrassed about the source of the server socket.
java.net.SocketException: Broken pipe (Write failed)
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)
at java.net.SocketOutputStream.write(SocketOutputStream.java:134)
at java.io.DataOutputStream.write(DataOutputStream.java:88)
at com.ns.data.ArticleData.sendPolling(ArticleData.java:272)
at com.ns.NewsServer$PollingThread.run(JNewsServer.java:89)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:750)

How to make a asnychron REST Server with communication to external hardware

I am currently working on a REST server in Spring Boot that also communicates with external hardware via USB or TCP/IP. A command is sent to the external device, then I wait 2 seconds for the response and return it to the RestController.
For the USB communication I am currently using jSerialComm. For the TCP/IP communication I use sockets.
The whole thing also works so far when I use Thread.sleep. However, I would prefer it to be more dynamic, i.e. without the sleep, because TCP/IP can cause delays.
For me Java and REST are still new. Is there a way to let the server communicate asynchronously with the hardware?
#RestController
#RequestMapping("/api/v1")
public class CommController {
#GetMapping("/Version")
public String getVersion() {
Serial serial = new Serial();
String s_response = null;
s_response = serial.getVersion();
return s_response;
}
#GetMapping("/VersionTCPIP")
public String getVersionTCPIP() {
Serial serial = new Serial();
String s_response = null;
s_response = serial.getVersionTCPIP();
return s_response;
}
}
USB/serial-class:
public class Serial {
private static SerialPort port;
private static List<Byte> l_readBuffer;
private static final class MessageListener implements SerialPortDataListener
{
#Override
public int getListeningEvents()
{
return SerialPort.LISTENING_EVENT_DATA_AVAILABLE;
}
#Override
public void serialEvent(SerialPortEvent event)
{
if (event.getEventType() != SerialPort.LISTENING_EVENT_DATA_AVAILABLE)
return;
byte[] newData = new byte[port.bytesAvailable()];
int numRead = port.readBytes(newData, newData.length);
for (int i = 0; i < numRead; i++)
{
l_readBuffer.add(newData[i]);
}
System.out.println("Read " + numRead + " bytes.");
}
}
public String getVersion() {
SerialPort[] ports = SerialPort.getCommPorts();
port = null;
for (SerialPort currentPort :
ports)
{
if (currentPort.getDescriptivePortName().contains("XXX"))
{
port = currentPort;
break;
}
}
Objects.requireNonNull(port).setBaudRate(9600);
port.setParity(SerialPort.NO_PARITY);
port.setNumStopBits(SerialPort.ONE_STOP_BIT);
port.setNumDataBits(8);
port.setFlowControl(SerialPort.FLOW_CONTROL_DISABLED);
//port.clearRTS();
port.setComPortTimeouts(SerialPort.LISTENING_EVENT_DATA_AVAILABLE, 5000, 5000);
port.openPort();
MessageListener listener = new MessageListener();
port.addDataListener(listener);
l_readBuffer = new ArrayList<>();
byte[] sendBuffer = new byte[5];
// fill sendBuffer
port.writeBytes(sendBuffer, sendBuffer.length);
try
{
Thread.sleep(2000);
} catch (Exception e)
{
e.printStackTrace();
}
System.out.println("Data raw: " + l_readBuffer.toString());
byte[] ba_responseBuffer = new byte[l_readBuffer.size()];
for (int i = 0; i < l_readBuffer.size(); i++)
{
ba_responseBuffer[i] = l_readBuffer.get(i);
}
String s_version = new String(ba_responseBuffer);
System.out.println("Version: " + s_version);
port.removeDataListener();
port.closePort();
return s_version;
}
public String getVersionTCPIP()
{
Socket socket;
String s_versionString = null;
try
{
socket = new Socket();
socket.connect(new InetSocketAddress(s_hostnameTCPIP, i_port), 1000);
byte[] ba_sendBuffer = new byte[1024];
Arrays.fill(ba_sendBuffer, (byte) 0x00);
// fill sendBuffer
// send data
DataOutputStream dOut = new DataOutputStream(socket.getOutputStream());
dOut.write(ba_sendBuffer); // write the message
dOut.writeInt(i_sendLength); // write length of the message
dOut.flush();
try
{
Thread.sleep(2000);
} catch (Exception e)
{
e.printStackTrace();
}
byte[] ba_responseBuffer = new byte[0];
if (socket.isConnected())
{
try
{
InputStream inFromServer = socket.getInputStream();
DataInputStream dIn = new DataInputStream(inFromServer);
synchronized (dIn)
{
int length = dIn.available();
ba_responseBuffer = new byte[length];
// receive data
dIn.readFully(ba_responseBuffer);
}
} catch (IOException ex)
{
ex.printStackTrace();
}
String s_version = new String(ba_responseBuffer);
System.out.println("Version: " + s_version);
s_versionString = s_version;
socket.close();
}
} catch (IOException e)
{
e.printStackTrace();
}
return s_versionString;
}
}

java.io.StreamCorruptedException: invalid stream header: 70707070

So I have seen a lot of different questions like this but no definitive help, at least to my understanding or my personal application. I am making a socket "chat room" program that allows the user to send images to selected users through a central server. I can establish the clients to connect but when sending an image this error occurs. Here is my code:
Client:
Thread thread = new Thread() {
#Override
public void run() {
try {
s = new Socket("localhost", 4000);
while (s.isConnected()) {
oos = new ObjectOutputStream(s.getOutputStream());
if (!initialized) {
oos.writeObject(identity);
oos.flush();
oos.reset();
initialized = true;
}
baos = new ByteArrayOutputStream(1000);
// Take screenshot
BufferedImage img = new Robot()
.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
// Write img to baos
ImageIO.write(img, "jpg", baos);
// Send image over socket
oos.writeObject(baos.toByteArray());
oos.flush();
oos.reset();
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
thread.start();
Central Server Home:
public Home() {
initComponents();
textView = new Terminal(terminal);
users = new CopyOnWriteArrayList<>();
Thread startServer = new Thread(new ServerStart());
startServer.start();
}
public class ServerStart implements Runnable {
#Override
public void run() {
try {
serverSock = new ServerSocket(4000);
terminal.append("Server started...\n");
while (true) {
// Detect client connection
Socket clientSock = serverSock.accept();
Thread thread = new Thread(new ClientHandler(clientSock));
thread.start();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
public class ClientHandler implements Runnable {
Socket socket;
public ClientHandler(Socket socket) {
this.socket = socket;
}
#Override
public void run() {
try {
User user = new User(socket);
terminal.append(user.getName() + " connected as " + user.getType() + "...\n");
if (user.getType().equals(User.TYPE_01)) {
users.add(user);
} else {
User client = findUser(user);
while(true){
user.sendScreen(client.receiveScreen());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
private User findUser(User user) {
for (User client : users) {
if (client.getCompany().equals(user.getCompany())) {
if (client.getName().equals(user.getName())) {
return client;
}
}
}
return null;
}
}
Central Server User:
public static final String TYPE_00 = "VIEWER";
public static final String TYPE_01 = "CLIENT";
private byte[] bytes;
private ObjectInputStream in;
private ObjectOutputStream out;
private String company, name, type;
public User(Socket socket) throws IOException {
this.out = new ObjectOutputStream(socket.getOutputStream());
this.in = new ObjectInputStream(socket.getInputStream());
setUserType();
}
public void sendScreen(byte[] bytes) {
try {
out.writeObject(bytes);
out.flush();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public byte[] receiveScreen() {
byte[] bytes = null;
try {
bytes = (byte[]) in.readObject();
} catch (Exception e) {
e.printStackTrace();
}
return bytes;
}
public String getCompany() {
return company;
}
public String getName() {
return name;
}
public String getType() {
return type;
}
public void setUserType()
{
String[] strings = null;
try{
strings = (String[])in.readObject();
type = strings[0];
company = strings[1];
name = strings[2];
} catch(Exception e){
e.printStackTrace();
}
}
Client Viewer:
Thread thread = new Thread() {
#Override
public void run() {
try {
Socket s = new Socket("localhost",4000);
String[] strings = { TYPE, "Vision", "cadams" };
while (s.isConnected()) {
if(!initialized){
System.out.println("initialized");
oos = new ObjectOutputStream(s.getOutputStream());
oos.writeObject(strings);
oos.flush();
oos.reset();
initialized = true;
}
ois = new ObjectInputStream(s.getInputStream());
byte[] bytes = (byte[]) ois.readObject();
BufferedImage img = ImageIO.read(new ByteArrayInputStream(bytes));
ImageIcon ico = new ImageIcon(
img.getScaledInstance(viewer.getWidth(), viewer.getHeight(), Image.SCALE_SMOOTH));
viewer.setIcon(ico);
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
thread.start();
}
I have done some extensive research and know that this could be from my streams looking like a bowl of ramen noodles but I haven't seen any sort of proposal on how to fix it in terms of source. I thank those who can contribute and please let me know if there is anything I can do to further understanding.
Don't keep creating new ObjectInput/OutputStreams. Use the same ones for the life of the socket.
NB while (s.isConnected() isn't valid. It doesn't magically become false when the peer disconnects. You need to handle end of stream and the various socket termination exceptions.

how to detect client's Internet speed from the response headers in java?

I have a server to get a response headers through which I detect the type of device. Is there any way I can get the Internet speed through response headers or any other method ?
Server_X:
public class Server_X {
static int count = 0;
public static void main(String args[]) {
Socket s = null;
ServerSocket ss2 = null;
System.out.println("Server Listening......");
try {
// can also use static final PORT_NUM, when defined
ss2 = new ServerSocket(4445);
} catch (IOException e) {
e.printStackTrace();
System.out.println("Server error");
}
while (true) {
try {
s = ss2.accept();
System.out.println("connection Established");
ServerThread st = new ServerThread(s);
count++;
System.out.println("total connections :" + count);
st.start();
}
catch (Exception e) {
e.printStackTrace();
System.out.println("Connection Error");
}
}
}
}
ServerThread:
class ServerThread extends Thread {
static String uagent, uaccept;
static String[] b;
static String[] c;
Server_X obj = new Server_X();
String line = null;
BufferedReader is = null;
PrintWriter os = null;
Socket s = null;
public ServerThread(Socket s) {
this.s = s;
}
public void run() {
try {
is = new BufferedReader(new InputStreamReader(s.getInputStream()));
os = new PrintWriter(s.getOutputStream());
} catch (IOException e) {
System.out.println("IO error in server thread");
}
try {
line = is.readLine();
while (line.compareTo("QUIT") != 0) {
os.println(line);
os.flush();
// System.out.println(line);
line = is.readLine();
b = line.split(":");
if (b[0].equals("User-Agent")) {
uagent = b[1];
// System.out.println(uagent);
}
c = line.split(":");
if (c[0].equals("Accept")) {
uaccept = c[1];
// System.out.println(uaccept);
}
UAgentInfo detect = new UAgentInfo(uagent, uaccept);
}
} catch (IOException e) {
line = this.getName(); // reused String line for getting thread name
// System.out.println("IO Error/ Client "+line+" terminated abruptly");
} catch (NullPointerException e) {
line = this.getName(); // reused String line for getting thread name
// System.out.println("Client "+line+" Closed");
} finally {
try {
System.out.println("Connection Closing..");
if (is != null) {
is.close();
// System.out.println(" Socket Input Stream Closed");
}
if (os != null) {
os.close();
// System.out.println("Socket Out Closed");
}
if (s != null) {
s.close();
// System.out.println("Socket Closed");
obj.count--;
System.out.println("Toatal connections (after closing):"
+ obj.count);
}
} catch (IOException ie) {
// System.out.println("Socket Close Error");
}
}// end finally
}
}
You didn't specify what protocol the server is using; I suppose is HTTP since you're catching "User-Agent" and "Accept". If I'm correct, there's no header with the information you're looking for, as you can check on https://en.wikipedia.org/wiki/List_of_HTTP_header_fields.

How to display html page when server requesting?

I have a problem with showing html page form localhost. Here is my method but I just get System.out.println("IN !") in loop (eclipse console). When I'm putting http://localhost:1600/myWebPage.html adress in my browser nothing happened. I'm wondering how to show web page or just some text in browser after typing http://localhost:1600/myWebPage.html. Is this path correct ?
public class ServerWWW {
//localhost:1600/
public static void main(String[] args) {
int portServerWww = 1600;
ServerSocket ss = null;
try {
ss = new ServerSocket(portServerWww);
System.out.println("Server WWW waiting .....");
while(true) {
Socket s = ss.accept(); // block
new ServiceWWW (s).start();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ss != null) {
try {
ss.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
class ServiceWWW extends Thread {
private Socket s = null;
private int counter;
public ObslugaWWW(Socket s) {
this.s = s;
}
public void run(){
try {
System.out.println("IN !"); //Loop
URL url = new URL("http://localhost:1600/myWebPage.html");
HttpURLConnection yc = (HttpURLConnection)url.openConnection();
yc.setRequestMethod("GET");
yc.setDoOutput(true);
yc.connect();
BufferedReader rd = new BufferedReader(new InputStreamReader(yc.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = "OK";
while ((line = rd.readLine()) != null){
sb.append(line + '\n');
}
System.out.println(sb.toString());
yc.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

Categories