OK, for the moment I'm trying to create an Android game, I have a thread running which is fine.
However, how can I determine the precise buffer size, and how to read it, it is not certain.
Currently this is my code:
if (! ThisPlayer.isHost) {byte [] incMsg = new byte [64]; Try {Socket = new datagramsocket (port); //socket.setSoTimeout (10); Datagram packet = new datagram packet (incMsg, incMsg.length); Socket.receive (packet); Log D. ("Receive game messages", "received" + incMsg.toString ()); } Hold (unknownhostexception error) {Log.e ("", "", fault); } Hold (exception mistake) {Log.e ("", "", err); } TestString = incMsg.toString (); } And {byte [] msg = "game on" .getBytes (); Try {string compip = "192.168.1.102"; String ip; If (thisPlayer.ipAddress.equals (compIP)) ip = "192.168.1.107"; Else ip = compIP; InetAddress sending IP = InetAddress.getByName (IP); Socket = new datagram (port); Datagram packet P = new datagram packet (msg, msg. lanf, sent IP, 5130); Socket.send (p); Log D. ("Sending a game message", "Sent"); Socket.close (); } Hold (unknownhostexception error) {Log.e ("", "", fault); } Hold (exception mistake) {Log.e ("", "", err); }} Socket.close (); This type of work is sending the host data, receiving customer data (I have commented on Atomim and the thread is continuing, so I know its receipt data) .
I convert the byte to [] string and then display it. Although what is going to be displayed is "[B 448xxxx", where xxxx is a series of repeating numbers / letters. Unfortunately, I am at that point where I am getting frustrated and now I am surrounded by the brain, and can not think of it for my life where I have gone wrong.
Tia
ps I also tried to make the same byte array without having to go outside without any fate: /
As far as I know, it means that an indicator for the byte array You can not specify it only in string, instead, use (new string (inMsg)) . In addition, since you did not initialize the array, you will receive garbage after data received (if the array is small).
Comments
Post a Comment