Game Development Community

Help sending files over a network connection.

by University Of Texas 1 · in Torque Game Engine · 07/08/2004 (3:01 pm) · 23 replies

I have a text file on the client computer that I want to send to the server for processing. I've been looking around the forums, but can't find a good way of accomplishing this. I was thinking sending the file via a script command, but I'm not sure which command would enable me to do so. Thanks!
Page «Previous 1 2
#1
07/10/2004 (8:18 am)
I think your question is more conceptual in nature:

The term 'file' refers to the operating system's reference to some data on the hard-drive. When you are sending a 'file' over a network, in actuality, the only thing being sent is the data contained in it. It is up to the application on the receiving end to know what to do with it. In the case of an FTP client/server, it provides a mechanism for writing that data to the hard-drive and setting a reference to it in the OS's file system. That said, in terms of Torque, your client application will read the raw data and send it to the server. The server will in-turn write the data to the hard-drive to create the 'file'.
#2
07/14/2004 (5:23 pm)
I guess what I'm asking for is there some script function that sends data over a connection. I need a starting place on which class is used for the connection, and I can work from there.
#3
07/14/2004 (5:37 pm)
Couldnt you just do this in a command to server as very simple way of achieving this?
#4
07/15/2004 (8:14 am)
You want to use commmandToClient and commandToServer most likely. You can also post NetEvents via script but commandTo* are much easier to work with. GameConnection is the class used for connections.
#5
07/18/2004 (2:40 pm)
What are some of the restrictions when sending via commandToServer/commandToClient, ie the maximum size, what data types, etc?
#6
07/19/2004 (11:41 am)
I don't *think* you can send any datatypes across a commandToServer/commandToClient connection. I think all that you can send across are strings and integers. The limitations would therefore be the same for other variables of those datatypes.

I'd recommend 3 commands. One to start the transfer, identifying who its coming from and what it is, a second command to send the file in 1024 byte chunks (or line by line), and a third command that told the server that the file was complete and to start processing.

Of course, I could be wrong. :)
#7
07/19/2004 (12:43 pm)
The packet size is 1500 bytes. If you're sending more than a few hundred bytes in a commandToClient call, that's bad. Bear in mind that if you use single quotes you'll use a string table entry which can save you space on commonly used strings, like player names. It'll just slow things down if you do something silly like transfer the file via the string table. :)

You can read the source code behind commandToClient and co. - it's in the game/net directory.
#8
07/19/2004 (3:15 pm)
Surely if you want to send a file you could implement your own file sending function using directplay or something?
#9
07/19/2004 (9:33 pm)
Transferring from within Torque is probably the best solution.
#10
07/21/2004 (7:59 am)
Thanks for all your help guys. I used Bryce's method and it works like a charm.
#11
07/21/2004 (3:33 pm)
Could you post the code you ended up with?

It would be much appreciated.
#12
09/09/2004 (1:39 pm)
Somewhere in the server scripts you send a command to client something to initiate the file transfer. Then in client.cs
function clientCmdTransferFile()
{	
	%file = new FileObject();   
	%file.openforRead($file_name);
	commandToServer('CreateFile', $filename); //Create the file on the server.
	while(!%file.isEOF())
	{
		%line1 = %file.readLine();
		if(%file.isEOF())
			commandToServer('TransferLine', $file_name, %line);  //Transfers the line and adds it to the server's file.
			}
	%file.close();   
	%file.delete();
}

And then server side in commands.cs:
function serverCmdCreateFile(%client, %filename)
{
	//Delete the previous file.
	$serverfilename = %filename;
	%file = new FileObject();
	%file.openforWrite(%filename);
	%file.close();
	%file.delete();
}

function serverCmdTransferLine(%client, %filename, %line)
{
	$serverfile = %filename;
	%file = new FileObject();
	%file.openforAppend($serverfile);
	%file.writeLine( %line);
	%file.close();
	%file.delete();
}

That code could probably be horribly optimised. And the transfer speed is really slow as well. I'm going to use it as a crutch until I figure out how to send files during the loading screen.
#13
09/10/2004 (3:50 am)
I will post a resource soon for binary file transfer between clients and server or client to client. Its using Torque script and only minimal change to engine. (It can be used for any kind of files, binary or text)

You just have to be patient, that resource will be released soon. Just need to make the resources presentable, create the readme and howto and first finish my holiday. ;)
#14
09/10/2004 (3:10 pm)
Claude -
i am *intensely* interested in what you're doing.

I would like to be able to add a [DTS] object to the game during runtime
which has not already been loaded into the game.

Relatedly,
how difficult is it to add a file to the resource manager during runtime ?

eg, ideally, one client creates a new texture or interiorinstance or [] on their machine,
and in the middle of a mission they can send it to the server which then redistributes it to all the clients.

Relatedly,
i notice that transferring game resources is really slow in the stock
connecting to server phase.
a 600KB texture was taking about eight minutes to go from the server to a LAN client.

Is this a simple bandwidth throttler which can be unthrottled ?

I can't say how glad i am to see other people working with this stuff!

Orion
#15
09/10/2004 (3:16 pm)
@Orion Elenzil

I don't know how to accomplish this, but to me it sounds pretty insecure. At least to start with, if someone manages to hack it.
#16
09/10/2004 (3:30 pm)
This is true.

However, our application is within the academic community
where i think we'll be able to trust the clients.

(please no cracks about how the internet itself made the same assumptions!)
:D

We may also simply allow only registered or known users to connect at all, etc.
#17
09/10/2004 (10:09 pm)
@Orion.

Ressource will probably be released next week. I put it together to test possibility to use Torque script to code an update server for our game. It work pretty fast but I only tested as a dedicated client and server. I don't know how this will behave if it's done during game play. Probably will generate serious lag. But still probably better than to use clientCmd/serverCmd combo.

For our project I plan to have it working as an application dedicated only to update and patching.
#18
09/11/2004 (1:12 am)
Again, you can't transfer large amounts of binary data using ClientCmd or Messages.
It's really not feasible :P
#19
09/11/2004 (1:47 pm)
Roger that.
#20
10/04/2004 (9:10 pm)
Any progress with the resource Claude-Alain Fournier? Not pushing, just interested :P
Page «Previous 1 2