socket makes browser hang...


Posted on 16th Feb 2014 07:03 pm by admin

I have a socket server, and I am having a problem at the moment...

A browser sends a http header request to the server, but... some browsers send one request for one file, and others want 2. For example, Google Chrome asks for two parts: The headers, and the post data.

Whereas Firefox sends it all at once.

Chrome Part 1:
Code: POST /postdata.php HTTP/1.1
Host: localhost:3333
User-Agent: Some Chrome string here
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://localhost:3333/postdata.php

Chrome Part 2:
Code: ------WebKitFormBoundaryHigb2TwanNRf4WQK
Content-Disposition: form-data; name="name"

ryan
------WebKitFormBoundaryHigb2TwanNRf4WQK
Content-Disposition: form-data; name="comment"

hello
------WebKitFormBoundaryHigb2TwanNRf4WQK
Content-Disposition: form-data; name="myFile"; filename="test.txt"
Content-Type: text/plain

hello! This is a test document!
Line 2
Line 3

Line 5
Line 6


End File!
------WebKitFormBoundaryHigb2TwanNRf4WQK
Content-Disposition: form-data; name="submit"

Post It!
------WebKitFormBoundaryHigb2TwanNRf4WQK--

Firefox Whole thing:
Code: POST /postdata.php HTTP/1.1
Host: localhost:3333
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 GTB5
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://localhost:3333/postdata.php
Content-Type: multipart/form-data; boundary=---------------------------491299511942
Content-Length: 566

-----------------------------491299511942
Content-Disposition: form-data; name="name"

ryan
-----------------------------491299511942
Content-Disposition: form-data; name="comment"

adfafqa
-----------------------------491299511942
Content-Disposition: form-data; name="myFile"; filename="test.txt"
Content-Type: text/plain

hello! This is a test document!
Line 2
Line 3

Line 5
Line 6


End File!
-----------------------------491299511942
Content-Disposition: form-data; name="submit"
Now the problem is that since firefox sends it once, my code makes Firefox hang because I have two socket_recv() one for the headers, and one for the post data, where the second socket_recv() just sits and waits but nothing is sent to it. In Chrome this works just fine, because data is send at two different times (headers and post data).

I don't really want to write code that checks a browser to see what the browser is and do something according the browser type, so is there a better way then what I have to get the data no matter what browser the user is using, and the code doesn't hang if the browser only sends headers once?

socket_recv($client, $headers, $max_post_size, 0);
if(preg_match("~^POST~", $headers)){
socket_recv($client, $post, $max_post_size, 0);
}else{
$post = '';
}

No comments posted yet

Your Answer:

Login to answer
324 Like 29 Dislike
Previous forums Next forums
Other forums

Problem displaying "scraped" XML data
I'm basicly having trouble displaying XML data scraped from an URL using cURL.

What the code

Need help with an email blocker for a guessbook
I am new with php and here is a simple guessbook page but I am being hit with spam from a group of t

setcookie and isset($_COOKIE(name)) seem very finnicky.
I'm currently playing around with a user system with login and registration. I'm trying to use cooki

Where am I going wrong
Been trying to work this out for hours

I have two tables called 'Genres' and 'Films'. Genre

retrieving images from mysql database using php
So I've been trying to figure out how to store images in a mysql database, and as far as i can tell

Backflush
I am looking for a report in SAP that would give me a list of all parts that are populated with a ba

storing results of a function - previous result overwritten with new result
I have created a function to validate input.

function validate_dimension($value,$name) {
<

This is driving me nuts!
This insert query looks to be alright, however I get this error:

QuoteYou have an error in yo

getting weird error..
okay, I'm getting an error on this particular function, something about the syntax in the mysql LIMI

single values into sql field
i have a form which i want the user to able to select multiple answers. But i want the answers to be

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash