473,386 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

C# client to Java ObjectInputStream - howto ?

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
Nov 15 '05 #1
2 8746
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.*********************@no-sp-am-eh-mail.com
remove all "no-sp-am-eh"s to reply
"Krzysztof Paz" <kp**@samorzad.pw.edu.pl> wrote in message news:OU**************@TK2MSFTNGP12.phx.gbl...
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

Nov 15 '05 #2
Krzysztof Paz wrote:
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,

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

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Offer | last post by:
Hi, I create a TCP connection between client & server and I need to send vectors via ObjectInputStreams back and forth (the client initiates the protocol). The connection is established...
1
by: Abhijit Gadekar | last post by:
Hello, I am getting a problem with objectinputstream and fileinputstream. Whenever I try to close a ObjectInputStream object it gives an Exception. And if I try to delete the associated file on...
1
by: Krzysztof Pa¼ | last post by:
Hi, I want to make simple client in phyton, which would be able to communicate with Java server using SSL sockets. There is the Java clients, which is doing this - so I'm pretty sure, that Java...
2
by: Dan | last post by:
Hello. I have recently tried upgrading the MySql connector for my servlet from 2.0.4 to 3.0.9. I have found a minor limitation in 2.0.4 and was hoping that 3.0.9 would fix it. However, now I...
4
by: rajbala | last post by:
Hi all, I am a newbie to JSP. I had a program in client and server by using java. But i want the same program in JSP. Please help me. server: // TCP server which waits...
3
by: blackraven1425 | last post by:
The ObjectInputStream in this code is giving a EOFException. Do I need to do anything special to get this to work withou the EOF exception? It gives the exception at the line of the first instance of...
3
by: bballpitcher65 | last post by:
ok...i have a very large program, but i keep getting this error.Exception in thread "main" java.lang.NullPointerException at flightlog.Totals.importFiles(Totals.java:29) at...
10
by: Humakt | last post by:
I'm trying to figure a good way to handle saving game state to file (common save/load game function in games). ObjectOutput/InputStream seems most promising so far. However,the object I'm saving...
2
by: yeshello54 | last post by:
so here is my problem...in a contact manager i am trying to complete i have ran into an error..we have lots of code because we have some from class which we can use...anyways i keep getting an error...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.