Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ConnectionWrapper {
- NetworkStream stream;
- StreamReader reader;
- Endpoint endPoint;
- bool endOfStream;
- int maxRetries = 5;
- public void connect() {
- // ... code to initialize a (TCP) socket to endPoint
- this.stream = new NetworkStream(socket, true);
- this.reader = new StreamReader(stream);
- }
- string readNextMsg() {
- try {
- string msg = reader.ReadLine();
- if (msg == "EOF") endOfStream = true;
- return msg;
- }
- catch (IOException e) {
- Exception ex = e;
- while (maxRetries-- > 0) {
- try { connect(); ex = null; }
- catch (Exception e2) { ex = e2; }
- }
- if (x != null) throw ex;
- }
- }
- }
- class ConnectionWrapper {
- NetworkStream stream;
- StreamReader reader;
- Endpoint endPoint;
- bool endOfStream;
- int maxRetries = 5;
- ArrayList arr;
- public void connect() {
- // ... code to initialize a (TCP) socket to endPoint
- this.stream = new NetworkStream(socket, true);
- this.reader = new StreamReader(stream);
- }
- private void initReceiverThread() {
- String line;
- while(stream.isConnected() && (line = reader.readLine()) != null) {
- // notify observers of a change
- arr.add(line);
- }
- }
- }
- public ArrayList getMessages() {
- ArrayList temp = arr;
- arr.clear();
- return temp;
- }
Add Comment
Please, Sign In to add comment