×

Discussion Board

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

    Thumbs up SocketConnection problem

    Hi friends,

    I am using SocteConnection for my application.

    My requirement is to fetch the media data from server and play that fetched data.

    Its working fine on WTK emulator as well as on Prototype_4_0_S60_MIDP_Emulator.

    But its not working on S60 3rd edition FP1 SDK for MIDP.

    Here is my sample code:

    url = socked://38.101.195.5:8000
    open socket connection(url);
    is = socket.openInputStream(); //is is inputstream.
    ....
    ....
    ....

    Manager.createPlayer(is);

    I dont know what might be the problem.

    can any one please help me?

    Thanks,
    Manoj.

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

    Re: SocketConnection problem

    at least there is a typo n your url.
    should be socket, not socked

    Also, what is the type of the media you are getting from the net. It is not clear from your post.

    Hartti

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

    Re: SocketConnection problem

    Quote Originally Posted by hartti View Post
    at least there is a typo n your url.
    should be socket, not socked

    Also, what is the type of the media you are getting from the net. It is not clear from your post.

    Hartti

    Hi hartti,

    sorry, I typed mistakenly in forum. Actually I put "socket://" in code.

    I am trying to get .mp3 file.

    Actually the connection is established properly. I opened input stream and output stream properly.

    here is the code which I have written:

    public int ConnectToServer()
    {
    int retval = -1; //fail
    try
    {
    String str = PrepareConnectCMD();

    display.setCurrent(null);
    si.setText("Going to ... Connected to server");
    System.out.println("Going to....Connected server");

    String tori_serverId = "socket://" + "38.101.195.5:8000";

    sc1 = (SocketConnection)Connector.open(tori_serverId);
    sc= (StreamConnection)Connector.open(tori_serverId);
    si.setText("Connected to server");

    try
    {
    is = sc.openInputStream();
    }
    catch (Exception e)
    {
    f.append("Error catched in inputstream:" + e.getMessage() +"\n");

    }
    try
    {
    os = null;
    os = sc.openOutputStream();
    if(null == os)
    {
    System.out.println("here is the mental case solve it!!!\n");
    }
    }
    catch (Exception e)
    {
    f.append("Error catched Outputstream:" + e.getMessage() + "\n");

    }


    // Start the thread for sending messages - see Sender's main
    // comment for explanation
    ////////////////////////////////
    // send Request to server
    //////////////////
    si.setText("Sending the request..");

    os.write(str.getBytes());
    os.write("\r\n".getBytes());
    si.setText("[SENT....]..");

    if (null == sc)
    {
    String dil1 = "connection not found";
    f.append(dil1);

    }
    else
    {
    String dil2 = "connection established";
    f.append(dil2);

    }
    display.setCurrent(f);
    ////////////////////////////////////////
    // ICY Response Header
    ////////////////////////////////////////
    int i = 0;
    while (true)
    {
    StringBuffer sb = new StringBuffer();
    int c = 0;
    System.out.println("going to read");

    try
    {
    while (((c = is.read()) != '\n') && (c != -1))
    {
    sb.append((char)c);
    System.out.print((char)c);
    }
    }
    catch (Exception err)
    {
    f.append("Error catched :" + err.getMessage() + "\n");
    }
    si.setText("Response read");
    sb.append((char)c);

    String sr = sb.toString();
    if (sr.startsWith(KSCIcyMetaintTag))
    {
    int endofStrIndex = sr.indexOf("\r\n");
    String metainvalStr = sr.substring(KSCIcyMetaintTag.length()+1, endofStrIndex);
    System.out.println("number:" + metainvalStr);
    m_metaInt = Integer.parseInt(metainvalStr,10);
    }
    if (sr.equals("\r\n"))
    {
    String d = "ok";
    si.setText("Staring OnlineRadio....");
    startREadingAudioStreamForEver();
    m_OnlineRadioStream = new cOnlineRadioStream(this.m_ByteQueue);
    retval = 1;
    m_ConnectionDone = true;
    break;
    }
    if (c == -1)
    {
    Alert a = new Alert("OnlineRadio connection error", "Please Verify OnlineRadio Server first", null, AlertType.ERROR);
    display.setCurrent(a);
    break;
    }

    }
    }
    catch (ConnectionNotFoundException cnfe)
    {
    Alert a = new Alert("Client", "Please Verify OnlineRadio Server first", null, AlertType.ERROR);
    a.setTimeout(Alert.FOREVER);
    a.setCommandListener(this);
    display.setCurrent(a);
    }
    catch (IOException ioe)
    {
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }

    return retval;
    }


    public String PrepareConnectCMD()
    {
    // HTTP Request
    final String KSCGet = "GET ";
    final String KSCHttp10 = " HTTP/1.0\r\n";
    final String KSCHost = "Host: ";
    final String KSCUserAgent = "User-Agent:S60InternetRadio/2.0\r\n";
    final String KSCAccept = "Accept:*/*\r\n";
    final String KSCIcyMetadata = "icy-metadata:1\r\n";
    final String KSCConnectionClose = "Connection:close\r\n\r\n";

    final String KSCConnectionClose1 = "\r\n\r\n";


    String HttpReq;
    String iPath = "/";
    System.out.println("SendRequestToServerL: No error, sending HTTP request (path has %d bytes)" + iPath);
    //first line of the request
    HttpReq = KSCGet + iPath + KSCHttp10;

    //next lines of the request
    HttpReq = HttpReq + KSCUserAgent + KSCAccept;

    //Indicate to the server we want to receive metadata
    HttpReq = HttpReq + KSCIcyMetadata + KSCConnectionClose1;

    //System.out.println(HttpReq);
    return HttpReq;


    }

    Thanks,
    Manoj.
    Last edited by manojkumar.m; 2008-08-27 at 11:42.

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 S40 5th Edition emulation, NCF 1.2 and BT dongle
    By nevillesatz in forum Bluetooth Technology
    Replies: 1
    Last Post: 2007-07-05, 10:52
  3. Problem with eglSwapBuffers and heap corruption
    By greatape in forum Symbian Media (Closed)
    Replies: 2
    Last Post: 2007-05-24, 03:35
  4. netcards - Problem with opening adapter
    By kernj in forum Symbian Tools & SDKs
    Replies: 5
    Last Post: 2007-01-10, 08:56
  5. Problem: S60 SDK for CW in PC with .NET
    By anttij in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2005-02-28, 11:36

Posting Permissions

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