@Override
	public void run() {
		InputStream is = null;
		try {
			is = m_socket.getInputStream();
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("Error! Stopping listening!");
			return;
		}
		MsgInputStream in = new MsgInputStream(is, m_defines);
		
		while(true) {
			try {
				Msg m = in.read();
				if (m == null) {
					synchronized(m_listeners) {
						for (TCPConnectionListener l : m_listeners) l.connectionClosed();;
					}
					disconnect();
					return;
				}
				synchronized(m_listeners) {
					for (TCPConnectionListener l : m_listeners) l.msg(m);;
				}
				if (Thread.currentThread().isInterrupted()) break;
			} catch(SocketException e) {
				//The connection has closed, exit silently
				synchronized(m_listeners) {
					for (TCPConnectionListener l : m_listeners) l.connectionClosed();;
				}
				return;
			} catch (IOException e) {
				e.printStackTrace();
				System.out.println("Error! Stopping listening!");
				break;
			}
		}
	}