Comments (2)
I went with
ByteBuffer buffer = ByteBuffer.allocate(message.length + Integer.BYTES);
buffer.putInt(message.length).put(message).rewind();
int chunkSize = 16 * 1024;
while (buffer.remaining() > 0) {
var amountToSend = buffer.remaining() <= chunkSize ? buffer.remaining() : chunkSize;
ByteBuffer part = buffer;
if (amountToSend != buffer.capacity()) {
// we need to allocation a new ByteBuffer because send calls ByteBuffer.array()
// which would return
// the whole byte[] and not only the slice. But the lib doesn't use
// ByteBuffer.arrayOffset().
var slice = buffer.slice(buffer.position(), amountToSend);
part = ByteBuffer.allocate(amountToSend);
part.put(slice);
}
buffer.position(buffer.position() + amountToSend);
localDataChannel.send(new RTCDataChannelBuffer(part, true));
log.debug(prefix() + " sent " + part.capacity() + " bytes");
}
for sending and
private ByteBuffer messageBuffer = null;
public final byte[] readMessage(ByteBuffer part) {
if (messageBuffer == null) {
int length = part.getInt();
notifyListeners(Direction.Inbound, State.Start, length, 0);
if (part.remaining() == length) {
var ret = new byte[length];
part.get(ret);
notifyListeners(Direction.Inbound, State.Complete, length, length);
return ret;
}
messageBuffer = ByteBuffer.allocate(length);
}
messageBuffer.put(part);
notifyListeners(
Direction.Inbound, State.Progress, messageBuffer.capacity(), messageBuffer.position());
if (messageBuffer.capacity() == messageBuffer.position()) {
notifyListeners(
Direction.Inbound, State.Complete, messageBuffer.capacity(), messageBuffer.capacity());
var ret = messageBuffer.array();
messageBuffer = null;
return ret;
}
return null;
}
plus null checking for receiving.
from webrtc-java.
look to this article https://stackoverflow.com/questions/35381237/webrtc-data-channel-max-data-size
plus you should understand that it's UDP and part of the data may lost in network, I saw this case on transmitting files great than 500kb on slow network connection (at the moment not sure is it bug of the library or success part of data transmission via webrtc technology)
from webrtc-java.
Related Issues (20)
- Receiving media data from client HOT 3
- if can? GainControl provide kAgcModeAdaptiveAnalog mode? HOT 1
- mvn install failed HOT 8
- Support linux-aarch64 HOT 1
- The offer I created cannot be saved, why is that?
- How to use WebRTC-Java to implement the server to push the UDP message on multiple browsers
- when demo will be publishes HOT 1
- Video cannot be obtained from the SRS service HOT 2
- Error in C++ Standard Library usage.
- Load library 'webrtc-java' failed
- Could you please provide APIs for encoding/decoding and audio mixing?
- WebRTC load failed when no aduio devices in Win10 HOT 2
- Loading native library in JNI HOT 1
- Request for a .jar library HOT 1
- Maven install webrtc-java-jni fails
- new PeerConnectionFactory failed
- How to solve the problem of bufferedAmount being full
- mvn failed HOT 2
- VideoTrack is not getting invoked on windows
- Leak of observer instances
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 webrtc-java.