 	*/
 	var hostName: String?
 	
+	private let queue = DispatchQueue(label: "message queue", attributes: .serial, target: nil)
+
 	private var browser: NetServiceBrowser?
 	
 	private var service: NetService?

	
	func writeMoreData() {
		if let logStream = self.logStream {
			if CFWriteStreamCanAcceptBytes(logStream) == true {
				if messageBeingSent == nil && messageQueue.count > 0 {
					messageBeingSent = messageQueue.remove(at: 0)
					sentCount = 0
				}
				if let msg = messageBeingSent {
					if sentCount < msg.count() {
						let ptr = msg.ptr().advanced(by: sentCount)
						let toWrite = msg.count() - sentCount
						let written = CFWriteStreamWrite(logStream, ptr, toWrite)
						if written < 0 {
							print("CFWriteStreamWrite returned error: \(written)")
						} else {
							sentCount = sentCount + written
							if sentCount == msg.count() {
								messageBeingSent = nil
							}
						}
					}

	}
	
	func pushMessageToQueue(_ encoder: MessageBuffer) {
		queue.async { 
			self.messageQueue.orderedInsert(encoder) { $0.seq < $1.seq }
			self.writeMoreData()
		}
	}

	func logMessage(_ message: String?, filename: String?, lineNumber: Int?, functionName: String?, domain: String?, level: Int?) {
