timeout now working, no more exceptions
This commit is contained in:
parent
62cc435a5f
commit
1e0cee1061
@ -18,13 +18,13 @@ public class BufferedNetworkStackClient {
|
||||
buf = ByteBuffer.allocate(1024);
|
||||
}
|
||||
|
||||
public void push(String s, String host, int port) throws IOException {
|
||||
public void push(String s, String host, int port) throws IOException, Exception{
|
||||
if (channel == null) {
|
||||
channel = DatagramChannel.open();
|
||||
}
|
||||
|
||||
InetSocketAddress dest = new InetSocketAddress(host, port);
|
||||
|
||||
|
||||
buf.clear();
|
||||
buf.put(CMD_PUSH);
|
||||
|
||||
@ -32,11 +32,15 @@ public class BufferedNetworkStackClient {
|
||||
buf.put(length);
|
||||
|
||||
buf.flip();
|
||||
channel.send(buf, dest);
|
||||
channel.send(buf, dest);
|
||||
|
||||
buf.flip();
|
||||
buf.clear();
|
||||
channel.receive(buf);
|
||||
channel.configureBlocking(false);
|
||||
|
||||
if(channel.receive(buf) == null){
|
||||
throw new Exception("ERROR: Buffer empty - not data recieved");
|
||||
}
|
||||
|
||||
byte[] receivedData = buf.array();
|
||||
String infoPacket = new String(receivedData).trim();
|
||||
@ -46,6 +50,7 @@ public class BufferedNetworkStackClient {
|
||||
int remoteBufSize = Integer.valueOf(info[0]);
|
||||
int sessionId = Integer.valueOf(info[1]);
|
||||
|
||||
System.out.println('4');
|
||||
sendChunks(s, dest, remoteBufSize, sessionId);
|
||||
}
|
||||
|
||||
@ -80,7 +85,7 @@ public class BufferedNetworkStackClient {
|
||||
}
|
||||
}
|
||||
|
||||
public String pop(String host, int port) throws IOException {
|
||||
public String pop(String host, int port) throws IOException, Exception{
|
||||
if (channel == null) {
|
||||
channel = DatagramChannel.open();
|
||||
}
|
||||
@ -88,7 +93,12 @@ public class BufferedNetworkStackClient {
|
||||
InetSocketAddress dest = new InetSocketAddress(host, port);
|
||||
channel.send(ByteBuffer.wrap(new byte[] { CMD_POP }), dest);
|
||||
|
||||
channel.receive(buf);
|
||||
channel.configureBlocking(false);
|
||||
|
||||
if(channel.receive(buf) == null){
|
||||
throw new Exception("ERROR: Buffer empty - not data recieved");
|
||||
}
|
||||
|
||||
byte[] receivedData = buf.array();
|
||||
String strReceived = new String(receivedData).toString().trim();
|
||||
|
||||
|
||||
@ -115,7 +115,9 @@ public class ClientGUI extends JFrame {
|
||||
e1.printStackTrace();
|
||||
} catch (IOException e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
} catch (Exception e3){
|
||||
textPane.setText(textPane.getText() + "\n" + e3.getMessage());
|
||||
}
|
||||
|
||||
textPane.setText(textPane.getText() + "\n" + received);
|
||||
}
|
||||
@ -129,7 +131,9 @@ public class ClientGUI extends JFrame {
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e3){
|
||||
textPane.setText(textPane.getText() + "\n" + e3.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user