mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 08:34:40 +00:00
Added sendFile method
Added a method to send an entire file over tcp.
This commit is contained in:
parent
a0250e6c6b
commit
5f0b3984fc
2 changed files with 39 additions and 0 deletions
|
|
@ -27,6 +27,7 @@
|
||||||
#include "console/consoleInternal.h"
|
#include "console/consoleInternal.h"
|
||||||
#include "core/strings/stringUnit.h"
|
#include "core/strings/stringUnit.h"
|
||||||
#include "console/engineAPI.h"
|
#include "console/engineAPI.h"
|
||||||
|
#include "core/stream/fileStream.h"
|
||||||
|
|
||||||
TCPObject *TCPObject::table[TCPObject::TableSize] = {0, };
|
TCPObject *TCPObject::table[TCPObject::TableSize] = {0, };
|
||||||
|
|
||||||
|
|
@ -404,6 +405,29 @@ void TCPObject::send(const U8 *buffer, U32 len)
|
||||||
Net::sendtoSocket(mTag, buffer, S32(len));
|
Net::sendtoSocket(mTag, buffer, S32(len));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TCPObject::sendFile(const char* fileName)
|
||||||
|
{
|
||||||
|
//Open the file for reading
|
||||||
|
FileStream readFile;
|
||||||
|
if(!readFile.open(fileName, Torque::FS::File::Read))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Read each byte into our buffer
|
||||||
|
Vector<U8> buffer(readFile.getStreamSize());
|
||||||
|
U8 byte;
|
||||||
|
while(readFile.read(&byte))
|
||||||
|
{
|
||||||
|
buffer.push_back(byte);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Send the buffer
|
||||||
|
send(buffer.address(), buffer.size());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
DefineEngineMethod(TCPObject, send, void, (const char *data),,
|
DefineEngineMethod(TCPObject, send, void, (const char *data),,
|
||||||
"@brief Transmits the data string to the connected computer.\n\n"
|
"@brief Transmits the data string to the connected computer.\n\n"
|
||||||
|
|
||||||
|
|
@ -425,6 +449,15 @@ DefineEngineMethod(TCPObject, send, void, (const char *data),,
|
||||||
object->send( (const U8*)data, dStrlen(data) );
|
object->send( (const U8*)data, dStrlen(data) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DefineEngineMethod(TCPObject, sendFile, bool, (const char *fileName),,
|
||||||
|
"@brief Transmits the file in binary to the connected computer.\n\n"
|
||||||
|
|
||||||
|
"@param fileName The filename of the file to transfer.\n")
|
||||||
|
{
|
||||||
|
return object->sendFile(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
DefineEngineMethod(TCPObject, listen, void, (U32 port),,
|
DefineEngineMethod(TCPObject, listen, void, (U32 port),,
|
||||||
"@brief Start listening on the specified port for connections.\n\n"
|
"@brief Start listening on the specified port for connections.\n\n"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,12 @@ public:
|
||||||
|
|
||||||
bool processArguments(S32 argc, ConsoleValueRef *argv);
|
bool processArguments(S32 argc, ConsoleValueRef *argv);
|
||||||
void send(const U8 *buffer, U32 bufferLen);
|
void send(const U8 *buffer, U32 bufferLen);
|
||||||
|
|
||||||
|
///Send an entire file over tcp
|
||||||
|
///@arg fileName Full path to file you want to send
|
||||||
|
///@return true if file was sent, false if not (file doesn't exist)
|
||||||
|
bool sendFile(const char* fileName);
|
||||||
|
|
||||||
void addToTable(NetSocket newTag);
|
void addToTable(NetSocket newTag);
|
||||||
void removeFromTable();
|
void removeFromTable();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue