public void write(String message) throws IOException {
		synchronized (this) {
			
			if (this.socket.isClosed()) {
				this.shutdown();
				return;
			}
			
			byte[] msg = message.getBytes();
			//System.out.println("Sending to client");
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			BufferedOutputStream os = this.out;
			//first byte is kind of frame
			baos.write(SINGLE_FRAME_UNMASKED);

			//Next byte is length of payload
			if (msg.length > 125) {
				baos.write(126);
				baos.write(msg.length / 256);
				baos.write(msg.length & 0xFF);
			}
			else {
				baos.write(msg.length);
			}

			//Then goes the message
			baos.write(msg);
			baos.flush();
			baos.close();
			//This function only prints the byte representation of the frame in hex to console
			//convertAndPrint(baos.toByteArray());

			//Send the frame to the client
			os.write(baos.toByteArray(), 0, baos.size());
			os.flush();
		}
	}