o******y 发帖数: 12 | 1 现在想用JAVA实现和远端通信,怎么定义message format on the wire.
For example, in C, the format is defined like this
struct CMD
{
uint16_t type;
uint16_t operation;
uint16_t field1;
uint16_t fields;
};
after populating this struct, I can call socket send to send out this
message.
In Java, What should I do to implement this ?
Thanks.
|
c*********e 发帖数: 16335 | 2 rmi,
找几个code example,copy,paste.不用自己造轮子。
【在 o******y 的大作中提到】 : 现在想用JAVA实现和远端通信,怎么定义message format on the wire. : For example, in C, the format is defined like this : struct CMD : { : uint16_t type; : uint16_t operation; : uint16_t field1; : uint16_t fields; : }; : after populating this struct, I can call socket send to send out this
|
p*****2 发帖数: 21240 | |
z*******3 发帖数: 13709 | 4 socket api
rmi
ejb remote
web service
jca
jms
太多了,随便选一个上 |
w**z 发帖数: 8232 | 5 depends, what is your workload? response time requirement? HA requirement?
client restriction?
【在 o******y 的大作中提到】 : 现在想用JAVA实现和远端通信,怎么定义message format on the wire. : For example, in C, the format is defined like this : struct CMD : { : uint16_t type; : uint16_t operation; : uint16_t field1; : uint16_t fields; : }; : after populating this struct, I can call socket send to send out this
|
g*****g 发帖数: 34805 | 6 楼上几位都上来就给太复杂的选项。我看你首选RMI,如果要从C的code搬,也可以考虑
写Server Socket, read/writeObject. 比如这个例子。
http://www.coderanch.com/t/205325/sockets/java/send-java-Object
【在 o******y 的大作中提到】 : 现在想用JAVA实现和远端通信,怎么定义message format on the wire. : For example, in C, the format is defined like this : struct CMD : { : uint16_t type; : uint16_t operation; : uint16_t field1; : uint16_t fields; : }; : after populating this struct, I can call socket send to send out this
|
p*****2 发帖数: 21240 | 7
感觉这些都比akka复杂呀?
【在 g*****g 的大作中提到】 : 楼上几位都上来就给太复杂的选项。我看你首选RMI,如果要从C的code搬,也可以考虑 : 写Server Socket, read/writeObject. 比如这个例子。 : http://www.coderanch.com/t/205325/sockets/java/send-java-Object
|
g*****g 发帖数: 34805 | 8 学akka更复杂。
【在 p*****2 的大作中提到】 : : 感觉这些都比akka复杂呀?
|
z*******3 发帖数: 13709 | 9 java+akka还好
【在 g*****g 的大作中提到】 : 学akka更复杂。
|
o******y 发帖数: 12 | 10 多谢,看了一下, 我的情况是对方SERVER不是我们的,人家只给了API
(就是我说的 C struct wire format) 的定义, 其中有每一个field的意思的定义,
有些field是16bit,有些是32bit,有些是signed, 有些是unsigned 的。
能用Send java object over socket这种方式吗? 另外,
我看java 有byte 类型, 对应的16 (OR 32) bit 的 unsigned 类型是哪个?
都是初级问题,让高手见笑了。
【在 g*****g 的大作中提到】 : 楼上几位都上来就给太复杂的选项。我看你首选RMI,如果要从C的code搬,也可以考虑 : 写Server Socket, read/writeObject. 比如这个例子。 : http://www.coderanch.com/t/205325/sockets/java/send-java-Object
|
|
|
l*********s 发帖数: 5409 | 11 好像没有对应的,自己封装一个吧
【在 o******y 的大作中提到】 : 多谢,看了一下, 我的情况是对方SERVER不是我们的,人家只给了API : (就是我说的 C struct wire format) 的定义, 其中有每一个field的意思的定义, : 有些field是16bit,有些是32bit,有些是signed, 有些是unsigned 的。 : 能用Send java object over socket这种方式吗? 另外, : 我看java 有byte 类型, 对应的16 (OR 32) bit 的 unsigned 类型是哪个? : 都是初级问题,让高手见笑了。
|
z*******3 发帖数: 13709 | 12 socket
java的socket是调用os的socket
你要看看java socket的api
然后自己动手测试一下
【在 o******y 的大作中提到】 : 多谢,看了一下, 我的情况是对方SERVER不是我们的,人家只给了API : (就是我说的 C struct wire format) 的定义, 其中有每一个field的意思的定义, : 有些field是16bit,有些是32bit,有些是signed, 有些是unsigned 的。 : 能用Send java object over socket这种方式吗? 另外, : 我看java 有byte 类型, 对应的16 (OR 32) bit 的 unsigned 类型是哪个? : 都是初级问题,让高手见笑了。
|
z*******3 发帖数: 13709 | 13 另外,你要send java object需要serializable接口
这个仅在java程序之间可以互相传,如果对方只提供c的接口的话
那恐怕不行
【在 o******y 的大作中提到】 : 多谢,看了一下, 我的情况是对方SERVER不是我们的,人家只给了API : (就是我说的 C struct wire format) 的定义, 其中有每一个field的意思的定义, : 有些field是16bit,有些是32bit,有些是signed, 有些是unsigned 的。 : 能用Send java object over socket这种方式吗? 另外, : 我看java 有byte 类型, 对应的16 (OR 32) bit 的 unsigned 类型是哪个? : 都是初级问题,让高手见笑了。
|
g*****g 发帖数: 34805 | 14 You can write byte stream according to the protocol.
【在 o******y 的大作中提到】 : 多谢,看了一下, 我的情况是对方SERVER不是我们的,人家只给了API : (就是我说的 C struct wire format) 的定义, 其中有每一个field的意思的定义, : 有些field是16bit,有些是32bit,有些是signed, 有些是unsigned 的。 : 能用Send java object over socket这种方式吗? 另外, : 我看java 有byte 类型, 对应的16 (OR 32) bit 的 unsigned 类型是哪个? : 都是初级问题,让高手见笑了。
|
w**z 发帖数: 8232 | 15 that seems to be the way to go. you have to decode the stream yourself.
【在 g*****g 的大作中提到】 : You can write byte stream according to the protocol.
|
c*********e 发帖数: 16335 | 16 serialize其实很简单的,比如
string A='GOOD';
string B='BAD';
serialize之后就是 A=GOOD&B=BAD
就是url传值的那个语法。
【在 z*******3 的大作中提到】 : 另外,你要send java object需要serializable接口 : 这个仅在java程序之间可以互相传,如果对方只提供c的接口的话 : 那恐怕不行
|
N*****m 发帖数: 42603 | 17 对方提供的api,message format具体是什么protocol?
你这个不仅仅是serialize,还要考虑endian问题
你用jvm的时候都是big endian,c/c++在linux和windows上基本上都是little endian
【在 o******y 的大作中提到】 : 现在想用JAVA实现和远端通信,怎么定义message format on the wire. : For example, in C, the format is defined like this : struct CMD : { : uint16_t type; : uint16_t operation; : uint16_t field1; : uint16_t fields; : }; : after populating this struct, I can call socket send to send out this
|