Connect with Expertise | Find Experts, Get Answers, Share Insights

C# client to Java ObjectInputStream - howto ?

Krzysztof Paz
 
Posts: n/a
#1: Nov 15 '05
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.Bin aryFormatter formatter =
new System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter();
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



Cezary Nolewajka
 
Posts: n/a
#2: Nov 15 '05

re: C# client to Java ObjectInputStream - howto ?


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.

--
Cezary Nolewajka
mailto:c.nolewajka-no-sp-am-eh@no-sp-am-eh-mail.com
remove all "no-sp-am-eh"s to reply


"Krzysztof Paz" <kpaz@samorzad.pw.edu.pl> wrote in message news:OU7IXB48DHA.1804@TK2MSFTNGP12.phx.gbl...[color=blue]
> 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.Bin aryFormatter formatter =
> new System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter();
> 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
>
>[/color]
Joerg Jooss
 
Posts: n/a
#3: Nov 15 '05

re: C# client to Java ObjectInputStream - howto ?


Krzysztof Paz wrote:[color=blue]
> 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.[/color]
[...][color=blue]
> 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...[/color]

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,

--
Joerg Jooss
joerg.jooss@gmx.net
- Try wether using J# you can send objects to the Java server or if that
produces .NET serialized

Closed Thread