Thursday, March 27, 2014

Android parameters of a variable can not be sent through the socket?


Sender sends a parameter value to the receiving end, can only be converted into a string value of the parameter sent to the receiving end of a string and then stop receiving further treatment to get this value?

There is a problem, can send multiple values ​​to a receiving terminal for processing? Novice solving!
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
a ndroid the socket with the other socket nothing special is not the same, not only send the string.
You can send a stream of bytes to each other, one can also send multiple parameters, as long as both sides like to follow the same protocol, which is received after the other know how these parameters extracted.

Reply:
cited a floor tantahe reply:
a ndroid the socket with the other socket nothing special is not the same, not only send the string.
You can send a stream of bytes to each other, one can also send multiple parameters, as long as both sides like to follow the same protocol, which is received after the other know how these parameters extracted.

How to send multiple parameters ah? Java seemingly no structure, right? This is how to send it? I am new to java, a lot of things are not very understanding for advice!
Reply:
For example, you start to resolve after sending "para1 + para2 + para3 + para4 + ....", the other received, encountered a plus sign, you know that is the beginning of the end of an argument and the next parameter. So you can put all the parameters extracted out.
This is one of the most simple protocol. You can also set the protocol complex and rigorous.
Reply:
reference to the third floor tantahe reply:
example, you send "para1 + para2 + para3 + para4 + ....", the other began to resolve after received, touch a plus sign, you know that is the beginning of the end of an argument and the next parameter. So you can put all the parameters extracted out.
This is one of the most simple protocol. You can also set the protocol complex and rigorous.

I wrote it and the same. Is to convert these numbers into strings, so send over, and then parse, but it feels a bit wrong. Do you think there is a problem?
Reply:
With json data transmission, very convenient.
Reply:
references, 5th Floor a394268045 reply:
with json data transmission, very convenient.

Examples can be affixed point code or post it?
Reply:
reference to the 6th floor tyaathome reply:
Quote: references, 5th Floor a394268045 reply:

With json data transmission, very convenient.

Examples can be affixed point code or post it?

In fact, you will need to send the object class will be serialized, implements Serializable
Then call writeObject (object)

Strong objects directly into the receiver on the line
Reply:
JsonObject json = new JsonObject ();
json.put (key1, value1);
json.put (key2, value2);
. socket.getOutputStream () write (json.toString () getBytes ().);
Reply:
reference to the 7th floor guoyoulei520 reply:
Quote: references to the 6th floor tyaathome reply:

Quote: references, 5th Floor a394268045 reply:

With json data transmission, very convenient.

Examples can be affixed point code or post it?

In fact, you will need to send the object class will be serialized, implements Serializable
Then call writeObject (object)

Strong objects directly into the receiver on the line

If I want to use android internal class how can I use it? For example, I would like to use MotionEvent class.
Reply:
reference to the 7th floor guoyoulei520 reply:
Quote: references to the 6th floor tyaathome reply:

Quote: references, 5th Floor a394268045 reply:

With json data transmission, very convenient.

Examples can be affixed point code or post it?

In fact, you will need to send the object class will be serialized, implements Serializable
Then call writeObject (object)

Strong objects directly into the receiver on the line

Hey Hey, answer me down ah.
Reply:
reference to the 9th floor tyaathome reply:
Quote: references to the 7th floor guoyoulei520 reply:

Quote: references to the 6th floor tyaathome reply:

Quote: references, 5th Floor a394268045 reply:

With json data transmission, very convenient.

Examples can be affixed point code or post it?

In fact, you will need to send the object class will be serialized, implements Serializable
Then call writeObject (object)

Strong objects directly into the receiver on the line

If I want to use android internal class how can I use it? For example, I would like to use MotionEvent class.

It certainly will not do ....
Reply:
reference to the 11th floor guoyoulei520 reply:
Quote: references to the 9th floor tyaathome reply:

Quote: references to the 7th floor guoyoulei520 reply:

Quote: references to the 6th floor tyaathome reply:

Quote: references, 5th Floor a394268045 reply:

With json data transmission, very convenient.

Examples can be affixed point code or post it?

In fact, you will need to send the object class will be serialized, implements Serializable
Then call writeObject (object)

Strong objects directly into the receiver on the line

If I want to use android internal class how can I use it? For example, I would like to use MotionEvent class.

That certainly will not do ....

 public boolean onTouchEvent (MotionEvent event) {
}

For example, I want to spread the service side event this variable there is no way?
Reply:
reference to the 12th floor tyaathome reply:
Quote: references to the 11th floor guoyoulei520 reply:

Quote: references to the 9th floor tyaathome reply:

Quote: references to the 7th floor guoyoulei520 reply:

Quote: references to the 6th floor tyaathome reply:

Quote: references, 5th Floor a394268045 reply:

With json data transmission, very convenient.

Examples can be affixed point code or post it?

In fact, you will need to send the object class will be serialized, implements Serializable
Then call writeObject (object)

Strong objects directly into the receiver on the line

If I want to use android internal class how can I use it? For example, I would like to use MotionEvent class.

That certainly will not do ....

 public boolean onTouchEvent (MotionEvent event) {
}

For example, I want to spread the service side event this variable there is no way?

You should want to get x y coordinate values ​​event inside of it, to re-write a class and serialize the value needed in your class repackaged and then sent to the next ..
Reply:
reference to the 13th floor guoyoulei520 reply:
you should want to get x y coordinate values ​​event inside of it, to re-write a class and serialization, the need value in your class repackaged and then sent to the next ..


Do you have a socket communication Serializable example?

I am here to say the receiving end does not find the class. I do not know how it was.
Reply:
http://blog.csdn.net/cq361106306/article/details/8107105
Reply:
cited 15 floor guoyoulei520 reply:
http://blog.csdn.net/cq361106306/article/details/8107105

I have sent a receiving end of one side, namely the two projects, I need to send that class were added to the two projects, then the receiving end will not find the kind of error reported. You help me find

 01-03 07:49:46.408: D / dalvikvm (14528): Late-enabling CheckJNI 
01-03 07:49:46.448: I / dalvikvm (14528): Turning on JNI app bug workarounds for target SDK version 8 ...
01-03 07:49:46.578: I / System.out (14528): start service
01-03 07:50:18.038: D / ViewRootImpl (14708): pckname = study.message.receive
01-03 07:50:18.048: I / System.out (14708): start service
01-03 07:52:08.608: I / System.out (14708): S: Error
01-03 07:52:08.608: W / System.err (14708): java.lang.ClassNotFoundException: com.example.touchevent.SaveInformation
01-03 07:52:08.618: W / System.err (14708): at java.lang.Class.classForName (Native Method)
01-03 07:52:08.618: W / System.err (14708): at java.lang.Class.forName (Class.java: 217)
01-03 07:52:08.618: W / System.err (14708): at java.io.ObjectInputStream.resolveClass (ObjectInputStream.java: 2297)
01-03 07:52:08.618: W / System.err (14708): at java.io.ObjectInputStream.readNewClassDesc (ObjectInputStream.java: 1656)
01-03 07:52:08.618: W / System.err (14708): at java.io.ObjectInputStream.readClassDesc (ObjectInputStream.java: 683)
01-03 07:52:08.618: W / System.err (14708): at java.io.ObjectInputStream.readNewObject (ObjectInputStream.java: 1799)
01-03 07:52:08.618: W / System.err (14708): at java.io.ObjectInputStream.readNonPrimitiveContent (ObjectInputStream.java: 787)
01-03 07:52:08.618: W / System.err (14708): at java.io.ObjectInputStream.readObject (ObjectInputStream.java: 1999)
01-03 07:52:08.618: W / System.err (14708): at java.io.ObjectInputStream.readObject (ObjectInputStream.java: 1956)
01-03 07:52:08.618: W / System.err (14708): at study.message.receive.Msg_REC_Background $ AndroidServer.run (Msg_REC_Background.java: 53)
01-03 07:52:08.618: W / System.err (14708): at java.lang.Thread.run (Thread.java: 856)
01-03 07:52:08.618: W / System.err (14708): Caused by: java.lang.NoClassDefFoundError: com / example / touchevent / SaveInformation
01-03 07:52:08.618: W / System.err (14708): ... 11 more
01-03 07:52:08.618: W / System.err (14708): Caused by: java.lang.ClassNotFoundException: com.example.touchevent.SaveInformation
01-03 07:52:08.628: W / System.err (14708): at dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java: 61)
01-03 07:52:08.628: W / System.err (14708): at java.lang.ClassLoader.loadClass (ClassLoader.java: 501)
01-03 07:52:08.628: W / System.err (14708): at java.lang.ClassLoader.loadClass (ClassLoader.java: 461)
01-03 07:52:08.628: W / System.err (14708): ... 11 more


This code is transmitted to the transmitting side
 
ObjectOutputStream ops = new ObjectOutputStream (socket.getOutputStream ());
ops.writeObject (saveInformation);


This is the receiving end receives the code
 
ObjectInputStream ois = new ObjectInputStream (client.getInputStream ());
SaveInformation saveInformation = (SaveInformation) ois.readObject ();


No comments:

Post a Comment