datagram

Is this statement correct in java?

旧城冷巷雨未停 提交于 2019-12-14 03:52:16
问题 I would like to do a data transfer between two computers using datagram socket.Iam using the following line this way : host=InetAddress.getByAddress("mypc",new byte[]{192,168,1,110}); but when i use the above statement i get this error :"Possible loss of precision" So i cast the int to bytes this way : InetAddress.getByAddress("mypc",new byte[]{(byte)192,(byte)168,(byte)1,(byte)110}); Would the above statement work now ??? 回答1: If you already have it in a string, just use getByName() :

Message only received once on the server on android app

痴心易碎 提交于 2019-12-14 03:16:54
问题 I have a server app and client app running separately on different android devices and am broadcasting the message in LAN from client app and server is listening but the problem is that the message is only received once at server, My client code is: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bt=(Button)findViewById(R.id.myButton); bt.setOnClickListener(new View.OnClickListener() { @Override public void onClick

What does FIONREAD of UDP (datagram) sockets return? [duplicate]

為{幸葍}努か 提交于 2019-12-14 00:53:52
问题 This question already has answers here : How do I get amount of queued data for UDP socket? (2 answers) Closed last year . Which one does ioctl of FIONREAD return, the next packet's length, or the length of all data in the buffer? Suppose there is a UDP server that receives 2 packets from a client 1 and another 2 packets from client 2 after client 1's packet. Then, what is the value of ioctl of FIONREAD , and what does readfrom return in that case? Client 1 : v two packets ++UDP Server got 4

Java DatagramSocket setting keep-alive option

人走茶凉 提交于 2019-12-13 20:28:38
问题 I'm trying to create a datagramsocket with and datagrampacket to send with the keep-alive option. I'm confused about how to set this though. Is there a simple way to do it like datagramsocket.setKeepAlive(true); ? EDIT: Sorry, I meant setting the time to live of a packet. Is there a way I can set it so if it isn't received, it will stay until it is received? 回答1: UDP is what's called connectionless protocol, i.e. no connection is established, you just send packets to an ip address/port tuple.

DatagramSocket temporarily stops receiving packets (Java)

有些话、适合烂在心里 提交于 2019-12-13 16:29:29
问题 I have programmed a plugin in Lua for a game that sends player information via a UDP packet (512 bytes) to a remote server that reads the data from the packet and aggregates all player information into an xml file (which can then be viewed on the web by all players so they can see eachother's current state). I have programmed the server in Java using a DatagramSocket to handle the incoming packets, however I noticed some strange behavior. After a certain period of time, the DatagramSocket

Receiving UDP in Java without dropping packets

▼魔方 西西 提交于 2019-12-13 07:10:07
问题 I have a library which I need to improve since it is dropping to many packets. I want to receive a RTP-Stream, but the streamer is sending bursts of 30-40 packets within a millisecond (MJPEG-Stream). I can see the packets being complete when monitoring traffic in Wireshark. But when trying to receive them in Java, I lose a lot of those packets. I have already been able to improve the libraries behavior by implementing a ring buffer that would constantly get filled whenever a packet is

Is it possible to send datagrams over TCP?

微笑、不失礼 提交于 2019-12-12 20:18:51
问题 In theory nothing prevents using TCP socket with SOCK_DGRAM. What you'll get is reliable datagram transport. Is this possible using Berkeley sockets? 回答1: What you want to take a look at is the SCTP Protocol. It provides the ability to send Datagrams over a reliable TCP style connection: In contrast to TCP, SCTP may be characterized as record-oriented, meaning it transports data in terms of messages, in a similar fashion to the User Datagram Protocol (UDP), so that a group of bytes (message)

How to bind DatagramSocket to particular port in Openshift

三世轮回 提交于 2019-12-12 02:38:53
问题 I am running siple java jar service on openshift which tried to connect with DatagramSocket and Getting this Exception: java.net.BindException: Permission denied at java.net.PlainDatagramSocketImpl.bind0(Native Method) at java.net.AbstractPlainDatagramSocketImpl.bind(AbstractPlainDatagramSocketImpl.java:96) at java.net.DatagramSocket.bind(DatagramSocket.java:397) at java.net.DatagramSocket.<init>(DatagramSocket.java:251) at java.net.DatagramSocket.<init>(DatagramSocket.java:304) at java.net

Application crashes while starting the new thread

感情迁移 提交于 2019-12-12 01:46:45
问题 I have a thread class when I start the thread and create the instance of thread class in the main class my app get crash. My main activity code for creating the thread is: broadcast broadcastobject=new broadcast(messages); broadcastobject.start(); My thread class is : public class broadcast extends Thread { private DatagramSocket socket; String str; private static final int TIMEOUT_MS = 10; WifiManager mWifi; EditText et; DatagramPacket packet; Button bt; private static final int SERVERPORT =

DatagramSocket not throwing SocketTimeout - Java

血红的双手。 提交于 2019-12-11 20:15:01
问题 My datagram socket is not throwing a SocketTimeout despite it being set and I'm not sure how to resolve this. The code is as follows. The thing is, if it doesn't receive any messages along this socket connection, it will timeout on the first run through. However, it successfully receives a message a couple of times, it won't timeout later on when a .receive is called. DatagramSocket serverSocket = new DatagramSocket(serverSyncPort); serverSocket.setSoTimeout(200); while(true) { receiveData =