×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    17

    Interoperability between JavaME and .NET

    Hi all,

    My problem: I have a program written in J2ME that requires data from a Bluetooth device (an RFID reader); however, the driver for the reader is only available as a .NET library in CSharp. Is there some way I can communicate between a J2Me application and the .NET application (e.g. using virtual serial ports)?


    Kind regards,

    William

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Interoperability between JavaME and .NET

    Hi William,

    a possible approach would be to use sockets to let the 2 applications communicate. This approach is often used when 2 different technologies must talk to each other within the same device, so it could work for you too, if I've correctly understood your situation.

    Pit

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    17

    Re: Interoperability between JavaME and .NET

    Hi,

    Thanks for your swift reply. So, you suggest using SocketConnection (using the loopback interface to stay local), where one application will act as a server, and one as a client? Regrettably, the device I use does not support the J2ME ServerSocketConnection API..


    William

  4. #4
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Interoperability between JavaME and .NET

    Yes, the basic approach is the one you describe. Anyway, if you have not access to SocketConnections, you could work with simple HTTP requests on Java side, listening for them within your C# app (so, putting up a basic HTTP server).

    Pit

  5. #5
    Registered User
    Join Date
    Sep 2008
    Posts
    17

    Re: Interoperability between JavaME and .NET

    Hi,

    The problem is that the data needs to be sent from the .NET application to the JavaME application, and the latter cannot listen for incoming connections. One solution could be to establish a TCP connection from the JavaME client (SocketConnection is available) to the .NET server, and keep it open to receive messages from the .NET application. Another solution could be to constantly send HTTP requests from the client to the server (so a polling approach); which one would be most interesting in your opinion?


    Thanks,

    William

  6. #6
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Interoperability between JavaME and .NET

    If Java ME app must listen for incoming messages from the .Net one, then SocketConnection would be more appropriate in my opinion: It would allow your Java ME app to receive messages in "real time" and would require less overhead than polling with continuous HTTP requests.

    Pit

  7. #7
    Registered User
    Join Date
    Sep 2008
    Posts
    17

    Re: Interoperability between JavaME and .NET

    Hi,

    Indeed, that seems to be the best option. Thanks a lot for your help!


    William

  8. #8
    Registered User
    Join Date
    Sep 2008
    Posts
    17

    Re: Interoperability between JavaME and .NET

    Hi,

    When I tried to implement this approach, I ran into the following:

    java.microedition.io.ConnectionNotFoundException: null

    The code that establishes the connection (and responsible for throwing the exception):

    Code:
    SocketConnection socket = (SocketConnection) 
    Connector.open("socket://localhost:80", Connector.READ_WRITE, true)'
    I am sure that my device supports SocketConnection (I've gotten it to work on an IP address in the local network), so the problem must be that I use localhost? I've tried substituting it for 127.0.0.1, omitting the arguments, changing the port (I've tried 13, 14, 9002, ..), but to no avail.

    Any ideas?

    William

  9. #9
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: Interoperability between JavaME and .NET

    First of all. For unsigned MIDlets socket connections to ports 80, 8080 and 443 are prohibited (throws security exception). so you need to use some other port.

    Secondly, you seem to working with the emulator, right? Instead of using localhost, try to use the real IP address of your computer.

    Hartti

  10. #10
    Registered User
    Join Date
    Sep 2008
    Posts
    17

    Wink Re: Interoperability between JavaME and .NET

    Hi,

    Thanks for your answer, but as I mentioned in my post I'm getting a ConnectionNotFoundException (not a SecurityException); secondly, the MIDlet is signed (also requesting the proper permissions in the JAD file) and running on an actual device, so it is probably not a security issue.

    I also mentioned that I tried using other ports, but I kept getting the same exception. The device is not connected to any network, so I tried replacing localhost with 127.0.0.1, but also to no avail.

  11. #11
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: Interoperability between JavaME and .NET

    Yep, my first comment was really a statement. Not really an answer. I should have been more clear in my writing.
    And signing basically makes my point a moot... :-)

    However, if I am not mistaken, the localhost really refers to the emulator.
    Someone mentioned using network loopback adapter and the using the loopback address (127.0.0.1) in similar situations, but I am not sure if this will solve your problem or not.

    Hartti
    Last edited by hartti; 2008-09-26 at 19:30. Reason: added a few words

  12. #12
    Registered User
    Join Date
    Sep 2008
    Posts
    17

    Re: Interoperability between JavaME and .NET

    Hi,

    So, it is not possible using 127.0.0.1 (or localhost) as IP address? Is there another way to access the loopback interface in J2ME? If not, another way to let 2 applications written in different languages communicate with each other ?

  13. #13
    Registered User
    Join Date
    Sep 2008
    Posts
    17

    Re: Interoperability between JavaME and .NET

    Hi everyone,

    I didn't manage to find a solution to the implementation issue below, so I implemented the other option, namely to let the .net app act as an HTTP server and have the JavaME app act as an HTTP client (downside, the JavaME app has to constantly poll to see whether new data is available). I used CompactWebServer as an HTTP server in compact .NET (I will probably throw a lot out to lessen the footprint, because I don't need much of it).


    Thanks anyway,

    William
    Last edited by wvwoense; 2008-10-01 at 18:39.

  14. #14
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    54

    Smile Re: Interoperability between JavaME and .NET

    Hi wvwoense and jappit!
    How are you all? I am now learning the J2ME. I would like to request one sample program connecting the J2ME and C# server. Normally, I can develop connection with J2ME and servlet using Http connection, but now I would like to connect J2ME program to the server(C#). Therefore, could you give me some sample? I would like to learn how the J2ME send the inputstream to C# program(the server) and how to receive the inputstream (from J2ME) in C#(the server). And then, I would like to request one more thing. Could you provide the documentation or instruction or some url for connecting the J2ME and C#?

    My email address is icecubebar@gmail.com and if possible, could you send me some sample? or could you give me some useful URL to learn the connection with J2ME and C#.

    Thank you,
    With Regards,
    sweetsweet24

  15. #15
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Interoperability between JavaME and .NET

    are you able to make a serverside C# script/server ?
    If sou you just have to search for http j2me on google and you wil find loads and loads of articles/tutorials/sample code to send an http request from j2me...

Similar Threads

  1. S60 + Visual Studio .Net 2003 Link error, but command line fine
    By redmeat in forum Symbian Tools & SDKs
    Replies: 3
    Last Post: 2005-12-22, 10:05
  2. Replies: 1
    Last Post: 2005-08-17, 14:30
  3. Replies: 6
    Last Post: 2004-09-17, 14:04

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×