I have a simple program either a server or client not sure which end it is. I open a port and accept messages on it. this works but it crashed last night when I revived a message via GET not POST. As you may have noticed I am very new to networking.
I am getting the transmission ok (the socket stuff) but i cant read the message.
this is the code i currently use.
//read HTTp header until the message size comes in
for(int eight = 0; eight < 8; eight++)
{
message = in.readLine();
LOGGER.fatal(eight);
LOGGER.fatal(message);
if(message.contains("Content-Length"))
{
try {
Pattern pattern = Pattern.compile("\\d+");
Matcher matcher = pattern.matcher(message);
while (matcher.find()) {
sizeInt = Integer.parseInt(matcher.group());
}
}
catch (Exception e)
{
LOGGER.fatal("size not found on header line", e);
//System.exit(-1);
}
}
}
LOGGER.fatal(sizeInt);
LOGGER.fatal("---------------------------");
char[] buffer =new char[sizeInt];
//skip blank line between header and message
message = in.readLine();
//read message
int fullRead = 0;
int thisRead = 0;
do
{
thisRead = in.read(buffer, fullRead, sizeInt - fullRead);
LOGGER.info(fullRead + " of " + sizeInt + " bytes of message read");
fullRead += thisRead;
}while(fullRead != sizeInt);
The problem iv’e got is that the GET method does not seen to have the size of the message in bytes and without that I don’t know how the read the message without it hanging.
I’m using java.
Can anyone suggest how I can edit this code to understand a GET message.
A GET request doesn’t have any content – there’s nothing to read. Any data has to be in the headers / URL.