×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    272

    Thumbs up Socket connection problem

    Hi all,

    I am writing an application which uses socket connection.

    I am able to establish a connection and can able to send the data.

    But I am unable to read the data.

    I am using eclipse 3.1 + carbide J1.5, S60 3rd edition FP1.

    I don't understand why I am not able to read the data.

    Here is my sample code.

    SocketConnection sc = (SocketConnection)Connector.open(url);
    InputStream is = sc.openInputStream();
    OutputStream os = sc.openOutputStream();

    os.write("hai!");
    int availableData = is.available();
    if(availableData==0)
    {
    System.out.println("data is not available.");
    }
    else
    {
    System.out.println("data is available:"+availableData);
    }


    while (((c = is.read()) != '\n') && (c != -1))
    {
    sb.append((char)c);
    System.out.print((char)c);

    }

    I am getting is.avaible as 0 in j2me.
    But when I tried the same code in normal java program I am getting some value and able to read the incoming data.


    Do I need to do any settings for the S60 emulator???
    Or
    Am I missing anything??

    Please help me.

    Thanks,
    Manoj.
    Last edited by manojkumar.m; 2008-09-01 at 11:33.

  2. #2
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: Socket connection problem

    Hi Manoj,
    Try out this option in socket connection.

    client = (SocketConnection) Connector.open(url,Connector.READ_WRITE);
    client.setSocketOption( SocketConnection.DELAY, 0 );
    client.setSocketOption( SocketConnection.KEEPALIVE, 0 );

  3. #3
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    272

    Re: Socket connection problem

    Quote Originally Posted by bhanuchandar.k View Post
    Hi Manoj,
    Try out this option in socket connection.

    client = (SocketConnection) Connector.open(url,Connector.READ_WRITE);
    client.setSocketOption( SocketConnection.DELAY, 0 );
    client.setSocketOption( SocketConnection.KEEPALIVE, 0 );
    Hi BhanuChandar,

    I have added the statements suggested by you.

    But I didn't get any response.

    Still I am getting is.available() as zero.

    What should I do?

    Thanks,
    Manoj.

  4. #4
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: Socket connection problem

    Hi,

    Why don't you try the HTTP connection rather than socket give it a try and see weather it is working. But I have not tried it socket connection in emulator. We are using the s40 emulator but there is no way to specify go through the socket connection. I think it is better to try in actual devise. Which will go through the socket connection.

    I.e S40(3rd and 5th) devise

  5. #5
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    272

    Re: Socket connection problem

    Quote Originally Posted by bhanuchandar.k View Post
    Hi,

    Why don't you try the HTTP connection rather than socket give it a try and see weather it is working. But I have not tried it socket connection in emulator. We are using the s40 emulator but there is no way to specify go through the socket connection. I think it is better to try in actual devise. Which will go through the socket connection.

    I.e S40(3rd and 5th) devise
    Do you mean that socket programming doesn't work on S60 emulator?

    will it work on S40 devices???

  6. #6
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: Socket connection problem

    Hi,

    I don't have any Idea about the S60 Emulator, But In our application also we are using the both the http and socket connection. We are using the S40 Emulators . In that there is no option to say go through socket connection.

    In our application we have a two loops send data through http and socket. We prefer application go through the http. if it fails the http connection we will try to connect over the socket. All the s60 devise will support http (As of my knowledge)

    It is better to try the application on real devise than the Emulator

Similar Threads

  1. Socket blocking problem
    By durgeshtrivedi in forum Mobile Java Networking & Messaging & Security
    Replies: 8
    Last Post: 2010-06-25, 14:30
  2. Problem with TCP Socket connection
    By SeppOS in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2008-01-01, 12:50
  3. Problem in establishing socket connection
    By elise_ee in forum Mobile Java General
    Replies: 4
    Last Post: 2005-08-30, 13:57
  4. Socket problem
    By defragger in forum Symbian
    Replies: 0
    Last Post: 2005-08-25, 08:16
  5. Problem with socket connection
    By prakashsainani in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2003-09-10, 15:33

Posting Permissions

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