×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    11

    Question sending message from j2se socket to j2me socket

    Hi everyone, im trying to do a mobile chat project. I have client phones and a servlet. Clients can login via servlet and after somebody login, i want to announce this event to other online clients like in msn. So there is an open serversocket on phones waiting for a connection and i created a socket in servlet like:

    SocketAddress sockaddr = new InetSocketAddress(/*ip of other online phone*/,1027);
    Socket socket = new Socket();
    socket.connect(sockaddr, 10000);


    I have a timeout exception at the latest line, i mean i couldn't reach j2me serversocket connection. Do you have any idea???

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: sending message from j2se socket to j2me socket

    Quote Originally Posted by gizyy View Post
    SocketAddress sockaddr = new InetSocketAddress( /*ip of other online phone*/ ,1027);
    This is your problem... the phone probably has no public IP address.

    Keep the socket connection from the phone open, so that the server can send information back to the phone. You won't be able to open a connection from the server to the phone.

    Graham.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    18

    Re: sending message from j2se socket to j2me socket

    Hi gizyy,

    It CAN be made to work in a limited fashion:

    When a cell user does any communications with your server, save the IP and PORT in a DB.
    Then you can TRY and send messages to that user based on events (other user login, msg etc)

    But the problem is that NAT servers in cellular networks are VERY quick to eliminate users from their tables.
    You can try and use KEEP_ALIVE and see what happens.

    I made it work for up to 20 seconds give or take. I guess the exact time is network dependent.

  4. #4
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: sending message from j2se socket to j2me socket

    Quote Originally Posted by gizyy View Post

    SocketAddress sockaddr = new InetSocketAddress(/*ip of other online phone*/,1027);
    Socket socket = new Socket();
    socket.connect(sockaddr, 10000);
    ?
    Where you are looking for to run the serlvet program?
    If you wanna run the client and server on the mobile itself then you have to use the WiFi connection...so that you can get the IP address of the device running with the server..
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. Sending SMS using J2ME
    By puneet78 in forum Mobile Java General
    Replies: 15
    Last Post: 2010-01-29, 05:05
  2. Replies: 0
    Last Post: 2009-01-15, 04:10
  3. Confirmation Message while sending the Message
    By Abhishek_karmakar in forum Symbian Networking & Messaging (Closed)
    Replies: 8
    Last Post: 2009-01-07, 06:23
  4. J2SE & J2ME Bluetooth Connection
    By J.J Yan in forum Bluetooth Technology
    Replies: 0
    Last Post: 2008-08-04, 05:34
  5. Sending long message
    By njoandy1 in forum Smart Messaging
    Replies: 2
    Last Post: 2005-02-06, 09:38

Posting Permissions

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