Comments (10)
So I gave it a try and came up with the following. However I do not seem to be able to get it to compile / work or even test it. I'll post it here in the hope that it isn't all too wrong.
/*
FileSend sends a file transmission request.
*/
func (t *Tox) FileSend(friendnumber uint32, fileKind ToxFileKind, filelength uint64, fileID uint8, filename string) (uint32, error) {
if t.tox == nil {
return 0, ErrBadTox
}
var cFileKind = C.TOX_FILE_KIND_DATA
switch ToxFileKind(fileKind) {
case TOX_FILE_KIND_AVATAR:
cFileKind = C.TOX_FILE_KIND_AVATAR
case TOX_FILE_KIND_DATA:
cFileKind = C.TOX_FILE_KIND_DATA
}
cFilename := (*C.uint8_t)(&[]byte(filename)[0])
var toxErrfileControl C.TOX_ERR_FILE_CONTROL
n := C.tox_file_send(t.tox, (C.uint32_t)(friendnumber), cFileKind, (C.uint64_t)(length), (C.uint8_t)(fileID), cFilename, (C.size_t)(len(filename)), &toxErrfileControl)
// check if all ok
filenumber := uint32(n)
if filenumber == math.MaxUint32 || ToxErrFileControl(toxErrfileControl) != TOX_ERR_FILE_CONTROL_OK {
return 0, ErrFuncFail
}
return filenumber, nil
}
/*
FileSendChunk sends a file chunk to a friend.
*/
func (t *Tox) FileSendChunk(friendnumber uint32, filenumber uint32, position uint64, data []byte, length uint64) error {
if t.tox == nil {
return ErrBadTox
}
cData := (*C.uint8_t)(&data[0])
var toxErrfileControl C.TOX_ERR_FILE_CONTROL
success := C.tox_file_send_chunk(t.tox, (C.uint32_t)(friendnumber), (C.uint32_t)(filenumber), (C.uint64_t)(position), cData, (C.uint64_t)(length), &toxErrfileControl)
if !bool(success) || ToxErrFileControl(toxErrfileControl) != TOX_ERR_FILE_CONTROL_OK {
return ErrFuncFail
}
return nil
}
from go-tox.
Thanks! I don't have much time atm but I'll give it a try this evening.
from go-tox.
Fantastic, thank you very much!
from go-tox.
Done. ;)
tox_file_seek
and tox_file_get_file_id
are still missing. Let me know when you need them.
from go-tox.
Thank you very much, works like a charm. Except: if I check for errors on calling t.FileSendChunk(friendNumber, fileNumber, position, data) in onFileChunkRequest, I always get an error back, specifically the "Function Failed" error (both in my code and in the example.go file if you catch the return of the function). The file is correctly received and valid, I have checked that. Not critical but a small bug. 😉
Otherwise I think I have all the functionality I'll require from here on out, so you should be safe from me for now. Cheers!
from go-tox.
Thanks for your bug report! The error is thrown because we try to call FileSendChunk
with len(data) == 0
when the file transfer is already completed. This is because onFileChunkRequest
is called with a length
of 0
when the file transfer is finished.
If the length parameter is 0, the file transfer is finished, and the client's resources associated with the file number should be released. [...]
For files with known size, Core will know that the transfer is complete after the last byte has been received, so it is not necessary (though not harmful) to send a zero-length chunk to terminate.
-- tox.h
I updated example.go to comply with this specification.
from go-tox.
Ah, so a bug on my side, specifically the user side. 😛 I've modified my code accordingly, now it works perfectly.
Thanks again!
from go-tox.
Hi! I found the time to add the missing C bindings. When updating, make sure to remove the unnecessary arguments from gotox.FileControl() (see examples/example.go#L165).
from go-tox.
Thanks for the warning, I'll update my code now to stay up to date.
EDIT: Update worked perfectly, everything still runs on my side.
from go-tox.
Nice to hear that :)
from go-tox.
Related Issues (11)
- could not determine kind of name for C.TOX_SAVEDATA_* HOT 3
- Example.go doesn't seem to connect HOT 6
- Friend request can take up to ~30 seconds or hang when running the Alice/Bob example. HOT 1
- Detection of when a file has been completely sent doesn't work for small files HOT 11
- Can't connect through proxy (Tor) HOT 1
- Windows HOT 2
- New "conference" API replacing old "group" API HOT 3
- Problem in CREATE_HOOK function HOT 4
- Update to c-toxcore? HOT 3
- Fatal error: tox/tox.h HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-tox.