md_lasalle

Members
  • Content count

    265
  • Joined

  • Last visited

Community Reputation

190 Neutral

About md_lasalle

  • Rank
    Member
  1. Passing byte array from C to PHP

    [quote][color=#1C2837][size=2]As long as you realize that your cheap web host will give you cheap service.[/size][/color][/quote] Part of my project consists of distributing connecting client over multiple servers, so in that case, another server would be used in case of a failure. Thanks for the reply, exactly what I needed to know.
  2. Passing byte array from C to PHP

    Interesting, I'm very new to PHP development and web stuff in general, I usually go with pure sockets with C programs, but I'm trying to come up with a cheap solution that can be hosted on cheap web hosts. I'm thinking into moving into JSon as well, but I need a few pointers. First, will I need libcurl to send JSon data from a c++ program ? Do I need to send this as a POST request ? Second, is reading from php://input the only way to retreive the JSon data from the receiving side ? What's the simplest ? Thanks hplus.
  3. Hey all, I've been struggling a bit on this. Basically, I'm building an array of bytes in the C program(can contain '\0' chars in it), which i then send to the PHP script using libcurl. Here's the sending code from C program (I omitted the usual initing stuff of libcurl) : [code] curl_formadd( &formpost, &lastptr, CURLFORM_COPYNAME, "dataField", CURLFORM_CONTENTSLENGTH, dataSize, CURLFORM_COPYCONTENTS, data, CURLFORM_END); [/code] My data actually gets there, but for some reason, I'm pretty sure I am not handling the data properly on the PHP side of things, and basically, PHP will cut some data because it thinks I am handling strings. In the example above, here's the content of my char buffer called "data" : [code] data[0] = '0' // length of the data packed in 4 digits for easier parsing data[1] = '0' data[2] = '1' data[3] = '8' data[4] = '6' // length of the string "myUUID" written next (doing so to remove '\0' in the byte array) data[5] = 'm' // the actual string data[6] = 'y' data[7] = 'U' data[8] = 'U' data[9] = 'I' data[10] = 'D' data[11] = 'x' // first byte of a 4byte integer (replaced some weird code by 'x') data[12] = 'x' // second byte of a 4byte integer (replaced some weird code by 'x') data[13] = 'x' // third byte of a 4byte integer (replaced some weird code by 'x') data[14] = 'x' // fourth byte of a 4byte integer (replaced some weird code by 'x') data[15] = '6' // length of the string "myNICK" written next (doing so to remove '\0' in the byte array) data[16] = 'm' // the actual string data[17] = 'y' data[18] = 'N' data[19] = 'I' data[20] = 'C' data[21] = 'K' [/code] With that information, how can I put the content of $_POST['dataField'] safely in a var on the PHP side, so that i can then iterate over it with a simple FOR loop ? I can normally get the "0018" size to an int without issues, and then I get myUUID, but the rest, I'm not able to parse. Thanks.
  4. (C++) libCURL POST get response back issue

    For those of you interested, the issue was a bug in libcurl 7.16.1, updated to 7.32.1 and now everything works as expected.
  5. (C++) libCURL POST get response back issue

    It was indeed a bug in the libcurl version, FYI for everyone, do not use 7.16.2! Thanks hplus for your input.
  6. (C++) libCURL POST get response back issue

    Ok looking at this post : [url="http://stackoverflow.com/questions/5929971/c-curl-empty-reply-from-server-every-time"]http://stackoverflow.com/questions/5929971/c-curl-empty-reply-from-server-every-time[/url] it seems to be a bug with libcurl 7.16.2, which is the exact version I'm using, gonna move to latest now.
  7. (C++) libCURL POST get response back issue

    Thanks for the tips, so my first thing was to get a tool like Firebug to observe the response headers coming from the server. Obviously, I had to trigger this from a form in another php file using the POST method so that Firebug could actually catch it. This is what I have : [code] Response Headers Date Thu, 08 Dec 2011 02:02:21 GMT Server Apache X-Powered-By PHP/5.2.17 Keep-Alive timeout=5, max=100 Connection Keep-Alive Transfer-Encoding chunked Content-Type text/html Request Headers Host www.mydomain.com User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0.1) Gecko/20100101 Firefox/8.0.1 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 Connection keep-alive Referer http://www.mydomain.com/folder/submitTest.php [/code] From my perspective, everything looks good, but I'm not a web expert. I tried using the header() function in PHP as well, without any different result : [code] header('HTTP/1.1 200 OK'); header('Content-Type: text/html; charset=utf-8'); header('Content-Length: 3495');[/code] I just ran it with VERBOSE and some STDERR redirected to a file and this is what i have : [code] * About to connect() to www.mydomain.com port 80 (#0) * Trying 72.xx.xx.xx... * connected * Connected to www.mydomain.com (72.xx.xx.xx) port 80 (#0) > POST /folder/submitScore.php HTTP/1.1 Host: www.mydomain.com Accept: */* Content-Length: 50 Content-Type: application/x-www-form-urlencoded * Empty reply from server * Connection #0 to host www.mydomain.com left intact * server returned nothing (no headers, no data) * Closing connection #0[/code]
  8. Hello, this might seem obvious to some of you that has experience with libcurl, but for some reason I'm fiddling with this and can't put my finger on the problem. This is the code that sends the POST to a php page, it works 100%, as on the server I insert a record in a database when I receive the data, and all is fine. [code] CURL* easyhandle = curl_easy_init(); if( easyhandle ) { m_recBuf = new char[1024]; curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, data); curl_easy_setopt(easyhandle, CURLOPT_URL, m_url.c_str()); curl_easy_setopt(easyhandle, CURLOPT_WRITEFUNCTION, &WebQuery::WriteData); curl_easy_setopt(easyhandle, CURLOPT_WRITEDATA, m_recBuf); } res = curl_easy_perform(easyhandle); /* post away! */ [/code] curl_easy_perform returns [size="2"]CURLE_GOT_NOTHING(52)[/size] , no header or data from the server My issue now is that I need to find a way to get some response back from the call, I have declared a static function : [code] size_t WebQuery::WriteData( char *ptr, size_t size, size_t nmemb, void *userdata) { return size; }[/code] Even with a breakpoint, "return size;" never gets hit. On the server, in the php script, I echo this : [code]echo "OK";[/code] Is this the way a response should be sent ? Why is my WriteData function never called ? Thanks everyone. This post is actually a cross post from [url="http://www.gamedev.net/topic/616386-c-libcurl-post-get-response-back-issue/"]Link[/url] , thought I'd get a better response in this sub forum.
  9. Hello, this might seem obvious to some of you that has experience with libcurl, but for some reason I'm fiddling with this and can't put my finger on the problem. This is the code that sends the POST to a php page, it works 100%, as on the server I insert a record in a database when I receive the data, and all is fine. [code] CURL* easyhandle = curl_easy_init(); if( easyhandle ) { m_recBuf = new char[1024]; curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, data); curl_easy_setopt(easyhandle, CURLOPT_URL, m_url.c_str()); curl_easy_setopt(easyhandle, CURLOPT_WRITEFUNCTION, &WebQuery::WriteData); curl_easy_setopt(easyhandle, CURLOPT_WRITEDATA, m_recBuf); } res = curl_easy_perform(easyhandle); /* post away! */ [/code] EDIT: curl_easy_perform returns [size="2"]CURLE_GOT_NOTHING(52)[/size] My issue now is that I need to find a way to get some response back from the call, I have declared a static function : [code] size_t WebQuery::WriteData( char *ptr, size_t size, size_t nmemb, void *userdata) { return size; }[/code] Even with a breakpoint, "return size;" never gets hit. On the server, in the php script, I echo this : [code]echo "OK";[/code] Is this the way a response should be sent ? Why is my WriteData function never called ? Thanks everyone. EDIT2: Seems that I may be facing a firewall issue on the serverside.
  10. Weird VPS behavior with recvfrom()

    Doing some research, i seem to not be the only one with the issue : http://codeguru.earthweb.com/forum/showthread.php?t=327522
  11. Hello, we rented some Windows VPS around the world for our latest multiplayer game. The issue I'm seeing is that when a client closes its socket, instead of the server recvfrom() returning an error with the client's external ip/port, it returns with the client's internal local ip/port (ie. 192.168.0.x). What can be causing this behavior ? Is there a better way to match recvfrom() errors to the corresponding client on the server ? Why does it only happen when we test on a VPS ? Thanks. [EDIT] Also to note : we only see the behavior with people behind a home router. We can't reproduce the issue when people are connecting using the company's network, which seems to be weird seeing how complex the structure can be. [Edited by - md_lasalle on October 23, 2009 11:03:32 AM]
  12. Handling UDP resends

    Sorry for resurrecting this, just got back from vacations. Quote:Original post by ben_garney The issue is that routers tend to allocate bandwidth based on who's using it. If you are regularly using a certain amount of bandwidth then it assumes you will keep using that much. If you are jumpy (ie you use 5kb/sec for a while then jump to 40kb/sec then back down) then it introduces extra lag as the router has to reallocate bandwidth to meet the sudden demand. In some cases, the router may not have enough storage to keep the packets around until they can be sent and will drop them. In other words, user is playing game, something exciting happens, and suddenly user has a big lag spike - if you don't budget a fixed data rate. If this is true, then i will be padding my packets with some resends until i reach a minimum amount of data, probably based on the max number of players in the game. Thanks for the input.
  13. Handling UDP resends

    Yep, quite challenging. 20 updates per second is in most case overkill : that's why the PVS will come in handy. Also, since the server upload is the culprit, the server is not updating Entity A to all players in the same game frame. It is distributed over multiple frames to try and keep a constant upload rate on the server, as opposed to big bursts of data to send in one frame at any time.
  14. Handling UDP resends

    Quote:Original post by dmail If you say your packets are 600bytes and you have 16 players with an update every 20th of a second then you have a 8.78kbs upstream usage, which is too much for the xbox360 as the limit is 8kbs. I still need to optimize things with a PVS and whatnot :) Quote:Original post by hplus0603 What is your unit of re-send? Are you saying that if a user-level message has not been delivered in 500ms, that user-level message gets re-queued for physical packet inclusion? Yes, the safe user packet gets included in the next outgoing physical packet. Quote:Original post by hplus0603 In general, you want to track your physical packets with sequence numbers, and then "know" which user-level messages have "made it" or not by tracking which physical packets have made it across. I have sequence numbers, but instead of putting them per physical packet, i put them per user-level safe packet, but before sending them and affecting a sequence number, a merge a few user-level safe packets together, so i don't end up with too much overhead. Quote:Original post by hplus0603 In general, you also want to allow multiple physical packets to be outstanding before you get an ack from the other end. Once you have those two pieces implemented, doing "optimal" re-send of reliable messages into physical packets based on latency is mostly an exercise in accounting and adding/removing things onto keyed lists. Perhaps this is what you're already doing, in which case you're doing fine. But then the original question makes no sense to me? Yes this is what I'm doing, sorry if we misunderstood each other. My initial question is now irrelevant since it mostly depends on one's implementation. At least I got some nice inputs from the discussion. I am now using the average round trip time measured from the moment i send the safe packet to the moment i receive the ACK for it. I impose a certain threshold and now it seems to behave really well without killing my server bandwidth.
  15. Handling UDP resends

    Currently, I don't resend physical packets, since they can contain both safe/unsafe data. If a safe user packet needs to be resent, it will get merged in the next physical packet to send, in-front of the new data to be sent, until my maximum send size is reached (which is about 1200 bytes per packet on the xbox, and imposing the same limit on PC seems to be good enough for me, my packets rarely go over 600 bytes) It might not be the best approach, but it is definitely running smooth with 16 players and intense action, especially since I'm not sending at the same rate for every client on the map, so the upload on the server is distributed over multiple game logic frames. Going from there I'm still opened to recommendations that fits my current design.