datagram

IndexOutOfBoundsException with DatagramChannel.receive(buf);

戏子无情 提交于 2019-12-25 07:28:53
问题 I'm a complete noob when it comes to networking programming. I'm getting the following error: E/AndroidRuntime( 4095): Caused by: java.lang.IndexOutOfBoundsException: length=18, offset=0, buffer size=0 At the following line: SocketAddress servaddr = udpChannel.receive(rcvHskBuf); This is how I create the buffer ByteBuffer rcvHskBuf = ByteBuffer.allocateDirect(packetSize); For the sake of debugging I changed the argument (which can be changed in the app) from the default 1432 to 1432*20 as

NumberFormatException for valid number String

╄→尐↘猪︶ㄣ 提交于 2019-12-25 06:31:05
问题 I'm making a program that needs to receive data over the internet. It's doing so using DatagramSockets and receiving DatagramPackets. This all works fine, and the byte array it receives is the exact one I would expect. However, when I try to convert the byte array to a string, and subsequently to an integer, very strange things happen. Running the code below gives a NumberFormatException on the parseInt line: String length = new String(data, 1, data.length-1); System.out.println("length = "

NumberFormatException for valid number String

眉间皱痕 提交于 2019-12-25 06:30:06
问题 I'm making a program that needs to receive data over the internet. It's doing so using DatagramSockets and receiving DatagramPackets. This all works fine, and the byte array it receives is the exact one I would expect. However, when I try to convert the byte array to a string, and subsequently to an integer, very strange things happen. Running the code below gives a NumberFormatException on the parseInt line: String length = new String(data, 1, data.length-1); System.out.println("length = "

How to read /dev/log?

偶尔善良 提交于 2019-12-23 13:15:45
问题 I would like to directly access to syslog messages from Python by reading /dev/log . My (very limited) understanding is that the correct way is to read from there is to bind a datagram socket. import socket sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) sock.bind('/dev/log') sock.listen(1) while True: data, addr = sock.recvfrom(1024) print(data) Apparently /dev/log is in use: Traceback (most recent call last): File "readlog.py", line 4, in <module> sock.bind('/dev/log') OSError:

Why is Netty giving me only 768 Bytes from UDP messages

限于喜欢 提交于 2019-12-21 05:06:26
问题 I have set the "receiveBufferSize" option to 1024, but for some reason I'm still getting only 768 bytes in messageReceived. The header of the data indicates that size of the data being sent is 1004. Below is the initialization code for the server: public static void main(String[] args) throws Exception { ConnectionlessBootstrap b = new ConnectionlessBootstrap(new NioDatagramChannelFactory()); // Options for a new channel b.setOption("receiveBufferSize", 1024); System.out.println(b.getOptions(

Datagramsocket: how receive(…) handles fragmentation of a packet

谁说我不能喝 提交于 2019-12-20 02:35:28
问题 I came to know from my Professor that, a datagram packet sent using UDP socket gets fragmented in the lower layers and may arrive as multiple packets at the receiver end. For e.g, if I send a 1000 bytes data in a datagram packet, at the receiving end it might arrive as, say 2 bytes, 500 bytes, 12 bytes, and so on. Therefore, he suggested to do multiple receive(...) to receive the entire 1000 byte packet sent by the sender. Later when I went through the Java documentation for datagram socket

Datagramsocket: how receive(…) handles fragmentation of a packet

青春壹個敷衍的年華 提交于 2019-12-20 02:35:08
问题 I came to know from my Professor that, a datagram packet sent using UDP socket gets fragmented in the lower layers and may arrive as multiple packets at the receiver end. For e.g, if I send a 1000 bytes data in a datagram packet, at the receiving end it might arrive as, say 2 bytes, 500 bytes, 12 bytes, and so on. Therefore, he suggested to do multiple receive(...) to receive the entire 1000 byte packet sent by the sender. Later when I went through the Java documentation for datagram socket

File Channel reads/adds wrong data

匆匆过客 提交于 2019-12-20 01:39:24
问题 I am using a filechannel with a byte buffer to send packets over the network. My problem is that when the filechannel reads the last few bytes it appends the last bit of data from previous bytes read even though I am clearing the byte buffer after I write. For example, Byte Buffer size = 512 For the last iteration, the remaining bytes to send is 372. It reads the last 372 but it also appends another 140 bytes (512-372) to the end of it, and appears that last 140 bytes is from the previous 512

Packet loss while receiving UDP broadcast in android device

牧云@^-^@ 提交于 2019-12-19 02:47:28
问题 For receiving UDP broadcast packets from the server to an android device, i used a service class and listen for packets in a thread. It receives the packet successfully. The problem is that if multiple packets are being sent from the server in the same time then packet loss will be the result. I even tried with a queue and processing the received packets in separate thread then also i am not getting the packet. I am completely new to network programming any help would be widely appreciated

VoIP RTP Streaming from/to server (in Java) to/from android

℡╲_俬逩灬. 提交于 2019-12-17 14:44:23
问题 My target is to have a push-to-talk chat app in GSM/UMTS/LTE networks; initially I wanted use multicast addresses and peer-to-peer without overload the server; unfortunatly, after deep investigation, I discovered that multicast is not allowed in GSM/UMTS/LTE networks, therefore I have to use the server in order to bounce the VoIP packets. I' don't like very much this solution because I have to overload the server, but I didn't find any better solution. If you have an alternative solution is