C# client to Java ObjectInputStream - howto ?

K

Krzysztof Paz

Hi,
There is a Java (SUN 1.4) server which using Object Input/Output Streams at
SSL/Socket to communicate with Java clients.
Now there is a request for making C# Client for this server also.
SSL layer could be done with Org.Mentalis.Security.dll from seclib-1.0
Mentalis package - its fine...

But, threre is a problem:
How to properly communicate from C# language to Java.ObjectInputStream -
cause I've tried many times, and always get the Java exception about wrong
stream header.

I've tought about using such code:
....
Connection = new SecureSocket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp, options);
Connection.Connect(new IPEndPoint(Dns.Resolve(server).AddressList[0],
int.Parse(port)));
Send("GET_SERVER_VERSION.CSHARP.SSL.MENTALIS\r\n", "UNKNOWN HEADER");
....
protected void Send(string data, Header header) {
System.IO.MemoryStream memOut = new System.IO.MemoryStream();
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter =
new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
formatter.Serialize(memOut, data, header);
byte[] toSend = memOut.ToArray();
int sent = Connection.Send(toSend);
while(sent != toSend.Length)
{
sent += Connection.Send(toSend, sent, toSend.Length - sent,
SocketFlags.None);
}
}
....
- but I've no idea how to make proper header value - that would work...

So, the question is:
How to make proper conversation with Java Object Streams from C# language...
....receiving objects is also needed...

My data objects from/to java server usually are strings, int, longs, bytes,
dates, arrays and multidimensional arrays of its...

Do you have any ideas or advices for me ?

Regards,
Chris
 
J

Joerg Jooss

Krzysztof said:
Hi,
There is a Java (SUN 1.4) server which using Object Input/Output
Streams at SSL/Socket to communicate with Java clients.
Now there is a request for making C# Client for this server also.
SSL layer could be done with Org.Mentalis.Security.dll from seclib-1.0
Mentalis package - its fine...

But, threre is a problem:
How to properly communicate from C# language to
Java.ObjectInputStream - cause I've tried many times, and always get
the Java exception about wrong stream header. [...]
So, the question is:
How to make proper conversation with Java Object Streams from C#
language... ...receiving objects is also needed...

My data objects from/to java server usually are strings, int, longs,
bytes, dates, arrays and multidimensional arrays of its...

I wouldn't say it's impossible, but that requires a conversion of .NET's
class representation to the JRE's format. I wouldn't want to integrate two
applications at such a low level of abstraction.

I would implement a Java based facade that translates SOAP calls from your
..NET client to Java object I/O to the application server.

Cheers,
 
C

Cezary Nolewajka

Hi Krzysztof,

Adding to the email I sent you I found such information on the mentalis pages:

The .NET class library offers SSL support when you connect to an HTTP server, but unfortunately it does not offer SSL or TLS support for other Internet protocols.

I am not sure how it relates to non-http socket connections to your java server.

I am not an expert on SSL/TSL but did an implementation of SSL/TSL using OpenSSL library written in C++ and wrote a C# .Net wrapper. This worked with http or email (POP3/SMTP) servers for secure connections.

I suppose there is a problem with headers while negotiating SSL/TSL connection. Did you try non-secure connections between your C# and Java code? Give it a go and if it works, then try the OpenSSL. I might try to help you out with the implementation of the .Net wrapper.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top