Jump to content


Photo

Multiplayer file sending


  • Please log in to reply
11 replies to this topic

#1 master123

master123

    GMC Member

  • GMC Member
  • 57 posts
  • Version:GM8

Posted 26 June 2012 - 11:10 AM

i cannot find a local ip file transfer to every member on a cirtain server (voice chat that saves an audio and sends it)
So i found a code online somewhere but
1. i don't know if it will send it to every member because
2. it does not work except freezes both games atleast the server and the client

here it is

server script:

if (mplay_connect_status() = 0) { return 0; };
if (argument0 = "dialog") { argument0 = get_open_filename("All Files|*.*","*.*"); };
if (!file_exists(argument0) or argument0 = "") { return 0; };
var file, done, uploadString, count; file = file_bin_open(argument0,0); done = 0;
mplay_data_write(0,chr(3)+filename_name(
argument0));
while (!done) {
        if (mplay_data_read(0) = "") {
           uploadString = ""; count = 0;
           while (file_bin_position(file) < file_bin_size(file) and count < argument1) {
                   unploadString += chr(file_bin_read_byte(file));
                   count += 1;
           };
           if (file_bin_position(file) >= file_bin_size(file)) { done = 1; uploadString = chr(2)+uploadString;
           } else { uploadString = chr(1)+uploadString; };
           mplay_data_write(0,uploadString);
        };
};
return 1;

i had to add the code below to get rid of an error of unknown variable:
unploadString=0

NOW here is the client


if (mplay_connect_status() = 0) { return 0; };
if (string_char_at(string(mplay_data_read(
0)),1) = chr(3)) {
   var file, done, count, uploadString;
   file = file_text_open_write(working_directory+"\down"+string_delete(mplay_data_read(0),1,
1));
   file_text_close(file);
   file = file_bin_open(working_directory+"\down"+string_delete(mplay_data_read(0),1,1)
,1);
   mplay_data_write(0,"");
   done = 0;
   while (!done) {
           uploadString = string(mplay_data_read(0));
           if (string_char_at(uploadString,1) = chr(2)) { done = 1; };
           if (uploadString != "") {
              count = 2;
              while (count < string_length(uploadString)+1) {
                      file_bin_write_byte(file,ord(string_char_at(uploadString,count)));
                      count += 1;
              };
              mplay_data_write(0,"");
           };
   };
   file_bin_close(file);
   return 1;
};

return 0;

the file is not even created and both freeze!
so whats happening?
or is there another example for OFFLINE engine, i looked everywhere......
  • 0

#2 PrimuS

PrimuS

    GMC Member

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

Posted 26 June 2012 - 11:47 AM

Basically, for sending files using only a low-level networking library/standard mplay (never used the last tho), you may do this:
Server:
1. Send a file transfer invite to the client, containing filename and filesize in bytes, maybe also md5 or whatever.
1.1. If the client rejects it, exit.
2. Open the file in binary mode (read).
3. Read N bytes from it (don't forget about file_bin_seek()).
4. Send a message to client containing, in order:
1) size of the chunk sent in bytes, i.e. N;
2) the chunk itself, like, those bytes you just read in the same order.
5. Keep doing 3-4 until file ends.
6. Send a message indicating the transfer end.
7. Close the file, reset all the stuff.

Client:
1. Receive a file transfer invite from the server, check if the file already exists or whatever.
1.1. If want to, reject it.
2. Open the file in binary mode (write).
3. When received a message containing the file chunk, write it into the file, since you've got the size and bytes in order (again, don't forget about file_bin_seek()).
4. Keep doing 3 until received a transfer end message or the filesize exceeds the expected size.
5. Close the file.
6. Check if the size matches expected size (or md5, if you have it), use the file accordingly.

You can do that without while loops, like, in the step event of client/server processing objects or whatever, because while basically hangs the game dead if something goes wrong (server doesn't send data for a long time or whatever). That's how i did it in my own game.

EDIT:
Oh, wait, i think you just forgot to put 'file_bin_seek()' in there, so the program gets stuck reading the same byte again and again, since when you check for position, it's always the beginning.

Edited by PrimuS, 26 June 2012 - 11:50 AM.

  • 0

#3 master123

master123

    GMC Member

  • GMC Member
  • 57 posts
  • Version:GM8

Posted 26 June 2012 - 11:53 AM

Basically, for sending files using only a low-level networking library/standard mplay (never used the last tho), you may do this:
Server:
1. Send a file transfer invite to the client, containing filename and filesize in bytes, maybe also md5 or whatever.
1.1. If the client rejects it, exit.
2. Open the file in binary mode (read).
3. Read N bytes from it (don't forget about file_bin_seek()).
4. Send a message to client containing, in order:
1) size of the chunk sent in bytes, i.e. N;
2) the chunk itself, like, those bytes you just read in the same order.
5. Keep doing 3-4 until file ends.
6. Send a message indicating the transfer end.
7. Close the file, reset all the stuff.

Client:
1. Receive a file transfer invite from the server, check if the file already exists or whatever.
1.1. If want to, reject it.
2. Open the file in binary mode (write).
3. When received a message containing the file chunk, write it into the file, since you've got the size and bytes in order (again, don't forget about file_bin_seek()).
4. Keep doing 3 until received a transfer end message or the filesize exceeds the expected size.
5. Close the file.
6. Check if the size matches expected size (or md5, if you have it), use the file accordingly.

You can do that without while loops, like, in the step event of client/server processing objects or whatever, because while basically hangs the game dead if something goes wrong (server doesn't send data for a long time or whatever). That's how i did it in my own game.

EDIT:
Oh, wait, i think you just forgot to put 'file_bin_seek()' in there, so the program gets stuck reading the same byte again and again, since when you check for position, it's always the beginning.


so the file_bin_seek() goes to the client?

Edit:
where do i exactly put that?

Edited by master123, 26 June 2012 - 11:54 AM.

  • 0

#4 PrimuS

PrimuS

    GMC Member

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

Posted 26 June 2012 - 11:57 AM

file_bin_seek() basically sends the position from/to which you wanna read/write the byte, so you gotta call it every time before you read/write it, cause reading/writing a byte doesn't automatically move the file_bin_position().
So it would be something like that:
if (mplay_connect_status() = 0) { return 0; };
if (argument0 = "dialog") { argument0 = get_open_filename("All Files|*.*","*.*"); };
if (!file_exists(argument0) or argument0 = "") { return 0; };
var file, done, uploadString, count, pos; file = file_bin_open(argument0,0); done = 0; pos = 1;
mplay_data_write(0,chr(3)+filename_name(
argument0));
pos = 0;
while (!done) {
        if (mplay_data_read(0) = "") {
           uploadString = ""; count = 0;
           while (file_bin_position(file) < file_bin_size(file) and count < argument1) {
                   file_bin_seek(file, pos);
                   unploadString += chr(file_bin_read_byte(file));
                   count += 1;
                   pos += 1;
           };
           if (file_bin_position(file) >= file_bin_size(file)) { done = 1; uploadString = chr(2)+uploadString;
           } else { uploadString = chr(1)+uploadString; };
           mplay_data_write(0,uploadString);
        };
};
return 1;

and


if (mplay_connect_status() = 0) { return 0; };
if (string_char_at(string(mplay_data_read(
0)),1) = chr(3)) {
   var file, done, count, uploadString, pos;
   file = file_text_open_write(working_directory+"\
down"+string_delete(mplay_data_read(0),1,
1));
   file_text_close(file);
   file = file_bin_open(working_directory+"\down"
+string_delete(mplay_data_read(0),1,1)
,1);
   mplay_data_write(0,"");
   done = 0;
   pos = 0;
   while (!done) {
           uploadString = string(mplay_data_read(0));
           if (string_char_at(uploadString,1) = chr(2)) { done = 1; };
           if (uploadString != "") {
              count = 2;
              while (count < string_length(uploadString)+1) {
                      file_bin_seek(file, pos);
                      file_bin_write_byte(file,ord(string_char_at(uploadString, count)));
                      count += 1;
                      pos += 1;
              };
              mplay_data_write(0,"");
           };
   };
   file_bin_close(file);
   return 1;
};

return 0;

I didn't check the rest of the code, just added the function.

Edited by PrimuS, 26 June 2012 - 12:02 PM.

  • 0

#5 master123

master123

    GMC Member

  • GMC Member
  • 57 posts
  • Version:GM8

Posted 26 June 2012 - 12:20 PM

Awesome its now working BUT
its 0 kb?

i really hope we get it!
  • 0

#6 PrimuS

PrimuS

    GMC Member

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

Posted 26 June 2012 - 12:22 PM

There's also a typo in the upper snippet, 'unploadString' instead of uploadString.

Edited by PrimuS, 26 June 2012 - 12:23 PM.

  • 1

#7 master123

master123

    GMC Member

  • GMC Member
  • 57 posts
  • Version:GM8

Posted 26 June 2012 - 12:28 PM

There's also a typo in the upper snippet, 'unploadString' instead of uploadString.


I had made it equal to zero because i had no idea why gm was complaining about it

BIG THANKS

I am giving you a +1 now!
  • 0

#8 master123

master123

    GMC Member

  • GMC Member
  • 57 posts
  • Version:GM8

Posted 26 June 2012 - 12:48 PM

It only sends to one person proberbly something in my code

can you do something like this

mplay_message_send();

where you can send to all players?

Edited by master123, 26 June 2012 - 12:51 PM.

  • 0

#9 master123

master123

    GMC Member

  • GMC Member
  • 57 posts
  • Version:GM8

Posted 26 June 2012 - 01:41 PM

If anyone sees this can they please help me because i am making this for my school.....
just need this bit and its all function!
  • 0

#10 PrimuS

PrimuS

    GMC Member

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

Posted 26 June 2012 - 03:12 PM

Well, try to connect to them one by one if sending files is all your program does.
  • 0

#11 master123

master123

    GMC Member

  • GMC Member
  • 57 posts
  • Version:GM8

Posted 26 June 2012 - 09:58 PM

the thing is I don't know how to send files to each person or how to specify where the file goes to......
e.g. with

"mplay_message_send(player,id,val) "

sends a message to the indicated player (either an identifier or a name; use 0 to send the message to all players). id is an integer message identifier and val is the value (either a real or a string). The message is sent in non-guaranteed mode. If val contains a string the maximal string length allowed is 30000 characters.

but how can I incoperate that kind of system where i can choose who to send FILES NOT MESSAGE using this kind of code below:


n = mplay_player_find();

for (i=1; i<n; i+=1) 
begin
//code here
end;

Edited by master123, 26 June 2012 - 10:03 PM.

  • 0

#12 master123

master123

    GMC Member

  • GMC Member
  • 57 posts
  • Version:GM8

Posted 27 June 2012 - 07:59 AM

ANYONE?????
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users