private void startReading()
	{
		
		if (!sock.isConnected() || sock.isClosed())
		{
			
			Disconnect();
			
			return;
			
		}
		
		buffer = new byte[buffer.length - bytesReceived];
		
		try
		{
			
			if (bytesReceived == -1) //end of stream
			{
				
				Disconnect();
				
				return;
				
			}
			
			bytesReceived += in.read(buffer);
			
			if (messageSize == -1) //still reading size of data
			{
				
				if (bytesReceived == 4) //received size information
				{
					
					messageSize = ByteBuffer.wrap(buffer).getInt(0);
					
					if (messageSize < 0)
					{
						throw new Exception();
					}
					
					buffer = new byte[messageSize];
					
					bytesReceived = 0;
					
				}
				
				if (messageSize != 0) //need more data
				{
					startReading();
				}
				
			}
			
			else
			{
				
				if (bytesReceived == messageSize) //message body received
				{
					
					StringBuffer sb = new StringBuffer();
					sb.append(new String(buffer));
					
					message.executeEvent(new MessageReceivedEvent(this, id, sb.toString()));
					
					//reset
					bytesReceived = 0;
					messageSize = -1;
					buffer = new byte[4];
					
					startReading(); //start reading again
					
				}
				else
				//need more data
				{
					startReading();
				}
				
			}
		}
		catch (Exception e)
		{
			
		}
	}