Jump to content


Photo

Http Dll 2


  • Please log in to reply
215 replies to this topic

#61 regular

regular

    GMC Member

  • New Member
  • 399 posts

Posted 21 September 2011 - 04:21 PM

Allows you to download web pages or files without blocking the game.

I got three questions:
1. I know that in order to download a file I need to write
rq=httprequest_create();httprequest_connect(rq,"mywebpa.ge/file.exe",0);
but how do I specify the download destination?
2. How do I check if the download has been canceled because of e.g. lost connection to internet or something else?
3. How do I check when the download has finished?
  • 0

#62 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3535 posts
  • Version:GM:Studio

Posted 21 September 2011 - 09:04 PM

You have to store it on a buffer, and then drop the buffer onto a file:
// Step event, assuming your code is on the create event or it has been called before this:
if httprequest_exists(rq)
{
    httprequest_update(rq);
    state = httprequest_get_state(rq);
    if state = 5
    {
        show_message("Download failed");
        httprequest_destroy(rq);
    }
    if state = 4
    {
        buffer = buffer_create();
        httprequest_get_message_body_buffer(rq,buffer);
        buffer_write_to_file(buffer, "C:\file.exe");
        buffer_destroy(buffer);
        show_message("Download complete");
        httprequest_destroy(rq);
    }
}

Edited by manuel777, 21 September 2011 - 09:06 PM.

  • 1

#63 regular

regular

    GMC Member

  • New Member
  • 399 posts

Posted 22 September 2011 - 10:21 AM

httprequest_get_state seems to return 4 way too early - it says Download complete when only 288 bytes out of 7kb are downloaded

edit: I simply needed to add httprequest_set_request_header(rq, "Connection", "keep-alive",true); so that the request doesnt die after the initial connection :)

new question: What will happen if I try to get the Content-Length header if it doesnt exist?

Edited by regular, 22 September 2011 - 04:50 PM.

  • 0

#64 Buff-Robotix

Buff-Robotix

    Who Took My Pants!?!

  • GMC Member
  • 314 posts

Posted 23 September 2011 - 07:23 AM

Did you try to read the message body to find out what pixdrop says?


If I understand how to use your dll function (it returns the message body from the website?) then PixDrop returned nothing.

Also, are you sure the phone number should be entered without the '-' characters?

I'm pretty sure it is supposed to be without. TxtDrop definitely is so I doubt they would be different. In any case I have been testing both just in case with no success.

ThanX
RobotiX
  • 0

#65 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 749 posts
  • Version:GM8.1

Posted 23 September 2011 - 12:39 PM

httprequest_get_state seems to return 4 way too early - it says Download complete when only 288 bytes out of 7kb are downloaded

edit: I simply needed to add httprequest_set_request_header(rq, "Connection", "keep-alive",true); so that the request doesnt die after the initial connection :)

Normally you shouldn't have to do this, the web server should close the connection only after the file has been downloaded completely. Setting 'connection' to 'keep-alive' means the server won't close the connection even when the transfer is complete, so you can send a second request with the same connection (the DLL doesn't support this though). I'm surprised this works for you ...

new question: What will happen if I try to get the Content-Length header if it doesnt exist?

The function will return an empty string.

@Buff-Robotix: I don't know why it doesn't work. Maybe they are blocking your request because they don't like automated requests?

Edited by Maarten Baert, 23 September 2011 - 12:41 PM.

  • 1

#66 Buff-Robotix

Buff-Robotix

    Who Took My Pants!?!

  • GMC Member
  • 314 posts

Posted 10 October 2011 - 02:43 AM

@Buff-Robotix: I don't know why it doesn't work. Maybe they are blocking your request because they don't like automated requests?



Possibly but I doubt it, its a very simple html based site.
They also have a similar upload based picture sending site http://www.pixdrop.com/uploader.php I think I will try this one.
  • 0

#67 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3535 posts
  • Version:GM:Studio

Posted 17 October 2011 - 04:10 AM

Is there any way to change the version of http on the header? so it looks like 'GET /file.php HTTP/1.1' (instead of the current 1.0)
  • 0

#68 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 749 posts
  • Version:GM8.1

Posted 17 October 2011 - 02:40 PM

No, because if you did that the server would send a HTTP 1.1 response, which the DLL doesn't support. But why do you want HTTP 1.1 anyway? You can still send HTTP 1.1 headers even if the request says HTTP/1.0 (that's just the version for the response).
  • 0

#69 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3535 posts
  • Version:GM:Studio

Posted 17 October 2011 - 05:16 PM

Because im triying to comunicate with a server wich only supports 1.1, it checks the version on the header to accept only 1.1 requests.. guess ill have to use js for this one :P
  • 0

#70 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • GMC Elder
  • 9328 posts
  • Version:Unknown

Posted 19 October 2011 - 11:30 PM

Because im triying to comunicate with a server wich only supports 1.1, it checks the version on the header to accept only 1.1 requests.. guess ill have to use js for this one :P

Or just build the requests yourself using the socket functionality of this DLL?

-IMP
  • 0

#71 Timothyfoster

Timothyfoster

    GMC Member

  • GMC Member
  • 79 posts

Posted 10 November 2011 - 03:21 PM

How would you check to see if there is internet connectivity before creating an http request and trying to connect?

I have this problem where if the internet is working, then the game runs fine. However, if the internet goes down then the game locks up. (which is why i want to test for connectivity before trying to connect)
  • 0

#72 regular

regular

    GMC Member

  • New Member
  • 399 posts

Posted 12 November 2011 - 02:29 PM

Is there any way to make the dll use port 21 instead of 80?
I need to use ftp
  • 0

#73 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 749 posts
  • Version:GM8.1

Posted 13 November 2011 - 01:28 PM

How would you check to see if there is internet connectivity before creating an http request and trying to connect?

I have this problem where if the internet is working, then the game runs fine. However, if the internet goes down then the game locks up. (which is why i want to test for connectivity before trying to connect)

The game shouldn't lock up, it should just fail to connect. If it locks up, there's probably something wrong with your code. Can you post the relevant code?

Is there any way to make the dll use port 21 instead of 80?
I need to use ftp

The name of the dll is 'Http Dll 2' for a reason: it supports HTTP, not FTP :). Just changing the port won't work. There are other DLLs for FTP though.
  • 0

#74 Timothyfoster

Timothyfoster

    GMC Member

  • GMC Member
  • 79 posts

Posted 13 November 2011 - 03:06 PM

Thanks for the reply, I realise now that It wasn't locking up the game... it was just taking a few seconds to respond which caused the game to stop.
btw "the machine" is really cool.. the physics are thought out well.. good job.

Edited by Timothyfoster, 13 November 2011 - 03:07 PM.

  • 0

#75 regular

regular

    GMC Member

  • New Member
  • 399 posts

Posted 26 November 2011 - 03:30 PM

What might be a reason Http Dll 2 to be failing to create any sockets under windows 7 and in the same time to create them and run fine under windows xp?
  • 0

#76 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 749 posts
  • Version:GM8.1

Posted 26 November 2011 - 07:08 PM

What might be a reason Http Dll 2 to be failing to create any sockets under windows 7 and in the same time to create them and run fine under windows xp?

I don't know, I'm using Windows 7 and it runs fine. Maybe it's a firewall setting?
  • 0

#77 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 749 posts
  • Version:GM8.1

Posted 22 January 2012 - 02:41 PM

Update: I've added UDP support, and there's also a small change to the way sockets work. socket_update has been replaced with socket_update_read and socket_update_write. This should make it easier to use the DLL correctly. Now your message loop should look like this:
// SERVER: step event of obj_player
// CLIENT: step event of obj_controller
var s;

/* (optional) send messages here */

socket_update_read(socket);

while socket_read_message(socket, global.buffer) {
    /* send and receive messages here */
}

/* (optional) send messages here */

s = socket_get_state(socket);
if s=4 {
    
    /* the connection was closed:
       SERVER: destroy this instance of obj_player.
       CLIENT: end the game or go back to the menu. */
    
    exit;
}
if s=5 {
    
    /* an error has occurred, the connection was lost:
       SERVER: destroy this instance of obj_player.
       CLIENT: display an error message, end the game or go back to the menu. */
    
    exit;
}

socket_update_write(socket);
You can also put socket_update_write(socket); in the end step event if you want. This makes it easier to make sure all messages are written before socket_update_write is called.
  • 0

#78 goresoft

goresoft

    GMC Member

  • GMC Member
  • 127 posts
  • Version:GM:Studio

Posted 23 January 2012 - 11:15 PM

your dll is the best network dll of this community, i speeded up my work thanks to HTTP2 Dll, Great job Maarten Baert!

Edited by goresoft, 23 January 2012 - 11:16 PM.

  • 0

#79 thedyingdragon

thedyingdragon

    GMC Member

  • GMC Member
  • 23 posts

Posted 02 February 2012 - 05:21 AM

I've been looking for a potential replacement for 39dll as I have found it is limiting for what I need to do.
So far the most potential i've seen is Net39 and this one. I tested it out both with using GM and C++ and it runs amazing and is easy to use

Im so glad I found this I may even consider upgrading my game and server in the next dev cycle
Theres a few other features I may add in as well

Nice Work!! :D
  • 0

#80 oslash

oslash

    GMC Member

  • GMC Member
  • 32 posts

Posted 11 March 2012 - 03:16 PM

im trying to replace 39dll from my game but this is really buggy

i dont know why but when i change things that shouldnt do any changes, i have a diferent result

for example i used
a=buffer_read_uint8(global.buffer);
switch (a)
{
//actions
}

it keep reading the first message received (always receiving the login message, even when using buffer_clear)
but when i used

switch (buffer_read_uint8(global.buffer))
{
//actions
}

it worked normally
  • 0

#81 oslash

oslash

    GMC Member

  • GMC Member
  • 32 posts

Posted 13 March 2012 - 03:13 AM

any ideas why does this happens?
  • 0

#82 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 749 posts
  • Version:GM8.1

Posted 13 March 2012 - 11:25 PM

That's strange, I suspect the problem is somewhere else in the code. Can you post all the code?
  • 0

#83 oslash

oslash

    GMC Member

  • GMC Member
  • 32 posts

Posted 15 March 2012 - 04:02 PM

That's strange, I suspect the problem is somewhere else in the code. Can you post all the code?


SERVER SIDE

step event of obj_connection (woops, my bad, edited)
var s;

socket_update_read(socket);

while socket_read_message(socket, global.buffer) {
    event_user(0);
}

s = socket_get_state(socket);
if s = 4 or s = 5{
    socket_destroy(socket)
    instance_destroy();
    exit;
}
user event 0
buffer_size = socket_get_read_data_length(global.buffer);                 
    global.feedback_download += buffer_size;

switch (buffer_read_uint8(global.buffer))
{
    case 0:
        scr_newuser(); //register a new user
    break;
    
    case 1:
        scr_login(); // login (duh)
    break;
    
    default:
        instance_destroy(); //disconnect
}

it works perfectly that way it just that if i use

a=buffer_read_uint8(global.buffer);
switch (a)
it doesnt works, always receives the first message received (always receives 1)
it isnt such a problem, but im curious of why it doesnt works this way

im suspecting the problem is because i use 2 objects, one for connections and another for logged in players (obj_connection and obj_player)

Edited by oslash, 15 March 2012 - 08:23 PM.

  • 0

#84 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 749 posts
  • Version:GM8.1

Posted 16 March 2012 - 08:10 PM

What happens if you use, say, 'abc' instead of 'a'? Is it possible that 'a' is used somewhere else? (this is exactly why you should always declare temporary variables with 'var')

Also, this can't be right:
buffer_size = socket_get_read_data_length(global.buffer);
That function expects a socket id, not a buffer id. You probably meant to use buffer_get_length.

If it still doesn't work, try reading the entire buffer with buffer_read_hex (before reading the first byte - don't forget use buffer_set_pos(global.buffer, 0) afterwards) so you can see what's actually being received (the problem could be on the client side as well).

Edited by Maarten Baert, 16 March 2012 - 08:11 PM.

  • 0

#85 oslash

oslash

    GMC Member

  • GMC Member
  • 32 posts

Posted 16 March 2012 - 10:03 PM

What happens if you use, say, 'abc' instead of 'a'? Is it possible that 'a' is used somewhere else? (this is exactly why you should always declare temporary variables with 'var')

Also, this can't be right:

buffer_size = socket_get_read_data_length(global.buffer);
That function expects a socket id, not a buffer id. You probably meant to use buffer_get_length.

If it still doesn't work, try reading the entire buffer with buffer_read_hex (before reading the first byte - don't forget use buffer_set_pos(global.buffer, 0) afterwards) so you can see what's actually being received (the problem could be on the client side as well).


the variable a isnt used anywhere, i already tried changing it, it doesnt do nothing
didnt noticed i used the buffer for socket_get_read_data_length, first i used buffer_get_lenght by intuition checking the script list, but did nothing, then i checked the documentation and ended using socket_get_read_data_lenght, didnt noticed i used the buffer, but somehow... it works the way i wanted

also i added the upload and download feedback after i had this problem

ill PM you my email, please help me via msn

Edited by oslash, 17 March 2012 - 02:09 PM.

  • 0

#86 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 749 posts
  • Version:GM8.1

Posted 18 March 2012 - 02:56 PM

@oslash: I rarely use MSN. Can just post (or PM) the GMK (both server and client)?
  • 0

#87 oslash

oslash

    GMC Member

  • GMC Member
  • 32 posts

Posted 27 March 2012 - 01:45 PM

ok, problem solved thanks
  • 0

#88 DefuzionGames

DefuzionGames

    GMC Member

  • GMC Member
  • 1439 posts
  • Version:Unknown

Posted 29 April 2012 - 11:10 PM

is there an example script to show how to download entire files freezing the game while the file downloads
  • 0

#89 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 749 posts
  • Version:GM8.1

Posted 02 May 2012 - 07:03 PM

Yes:
http://www.maartenba.../#usage-example
Scroll down to 'Normal request without blocking the game'.
  • 0

#90 DefuzionGames

DefuzionGames

    GMC Member

  • GMC Member
  • 1439 posts
  • Version:Unknown

Posted 03 May 2012 - 12:29 PM

Yes:
http://www.maartenba.../#usage-example
Scroll down to 'Normal request without blocking the game'.


But i just said I WANT to freeze the game?
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users