Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor alicenan88's Avatar
    Join Date
    Nov 2008
    Posts
    54
    Hello everyone,

    I am a newbie on symbian development.Now, my boss asked me to implement a function like that ,we need to build a socket server,but on the client side, there is a javascript programming to send request in format of HTTP or (restful) , such as Get http://127.0.0.1:8080/data/name of user, then the server need to reply the information of the user to the javascript .

    I just don't know is it possible? and if so, how to implement the socket server part, is there anyone can give me some example or useful link? thank u so much!!

    Waiting for ur great help.

    Faithfully yours

  2. #2
    Nokia Developer Expert symbianyucca's Avatar
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    28,664
    Easier way would be to take the actual HTTP eample and use it, othervise you would need to make the headers etc. by yourself when sending teh request.

  3. #3
    Regular Contributor alicenan88's Avatar
    Join Date
    Nov 2008
    Posts
    54
    where I can find a server example, what I found is all http client,that connected to a server already existed . do u have any suggestion?Thank u so much

  4. #4
    Nokia Developer Expert symbianyucca's Avatar
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    28,664
    Check the menu on top of the page, tools, docs & code --> Code examples might be a good place to start looking from..

  5. #5
    Regular Contributor alicenan88's Avatar
    Join Date
    Nov 2008
    Posts
    54
    yes,I know, I have checked a long long time,but all are about how to set up a client part to connect the existed server part

  6. #6
    Registered User yunert's Avatar
    Join Date
    Oct 2009
    Posts
    16
    I´m not a Nokia Expert but as far as I know there isn´t any open source implementation of such basic thing.
    Rgds.

  7. #7
    Nokia Developer Moderator wizard_hu_'s Avatar
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    27,680
    You know what?
    Here is my single-shot "web server":
    Code:
    void MainL()
    {
        _LIT(KHelloWorld,"Hello World");
        _LIT(KFormat,"%d\n");
    
        CConsoleBase *console=Console::NewL(KHelloWorld,TSize(KConsFullScreen,KConsFullScreen));
        CleanupStack::PushL(console);
        
        RSocketServ sockserv;
        User::LeaveIfError(sockserv.Connect());
        CleanupClosePushL(sockserv);
        
        RConnection connection;
        User::LeaveIfError(connection.Open(sockserv));
        User::LeaveIfError(connection.Start());
        CleanupClosePushL(connection);
        
        RSocket servsock;
        User::LeaveIfError(servsock.Open(sockserv,KAfInet,KSockStream,KProtocolInetTcp,connection));
        CleanupClosePushL(servsock);
        
        TSoInetInterfaceInfo ifinfo;
        TPckg<TSoInetInterfaceInfo> ifinfopkg(ifinfo);
        
        TSoInetIfQuery ifquery;
        TPckg<TSoInetIfQuery> ifquerypkg(ifquery);
        
        TInetAddr addr;
        
        TUint32 iap;
        _LIT(KIapId,"IAP\\Id");
        User::LeaveIfError(connection.GetIntSetting(KIapId, iap));
    
        User::LeaveIfError(servsock.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl));
        while(KErrNone==servsock.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, ifinfopkg))
        {
            ifquery.iName = ifinfo.iName;
            if(KErrNone!=servsock.GetOpt(KSoInetIfQueryByName, KSolInetIfQuery, ifquerypkg))
                break;
            if (ifquery.iZone[1] == iap)
            {
                if(ifinfo.iAddress.Address() > 0)
                {
                    addr = ifinfo.iAddress;
                    break;
                }
            }
        }
    
        {
        TBuf <100> buf;
        addr.Output(buf);
        
        _LIT(KNewLine,"\n");
        buf.Insert(0,KNewLine);
        buf.Append(KNewLine);
        console->Printf(buf);
        }
        
        RSocket socket;
        User::LeaveIfError(socket.Open(sockserv));
        CleanupClosePushL(socket);
        
        TRequestStatus status;
        User::LeaveIfError(servsock.SetLocalPort(80));
        User::LeaveIfError(servsock.Listen(4));
        servsock.Accept(socket,status);
        User::WaitForRequest(status);
        User::LeaveIfError(status.Int());
        
        CBufFlat *flat=CBufFlat::NewL(20);
        CleanupStack::PushL(flat);
        TBuf8<100> buf8;
        TSockXfrLength x;
        
        _LIT8(KDoubleNewLine8,"\r\n\r\n");
        
        while(status==KErrNone)
        {
            socket.RecvOneOrMore(buf8,0,status,x);
            User::WaitForRequest(status);
            flat->InsertL(flat->Size(),buf8);
            console->Printf(_L("%d %d\n"),buf8.Length(),flat->Size());
            if(flat->Size()>=4 && flat->Ptr(flat->Size()-4).Compare(KDoubleNewLine8)==0)
                break;
        }
        
        flat->ResizeL(flat->Size()*2);
        TPtr8 ptr8=flat->Ptr(0);
        ptr8.SetLength(ptr8.Length()/2);
        TPtr ptr=ptr8.Expand();
        console->Write(ptr);
       
        _LIT8(KResponse,"HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: text/html\r\nContent-Length: 5\r\n\r\nHello");
        socket.Write(KResponse(),status);
        User::WaitForRequest(status);
        
        CleanupStack::PopAndDestroy(5); // flat,socket,servsock,connection,sockserv
        
        CleanupStack::PopAndDestroy(); // console
    }
    It says 'Hello' to anyone who asks.

Similar Threads

  1. Menu System(-1) error
    By logan04x in forum Symbian C++
    Replies: 15
    Last Post: 2009-02-08, 08:57
  2. How to create .sis file...?
    By satishkatta in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 25
    Last Post: 2008-09-04, 12:43
  3. How to know Socket has read the full message form a server in SDK socket example?
    By Mohan Kumar in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2007-06-22, 16:26
  4. How to detect when the socket server is down???
    By winner22000 in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2006-09-08, 21:17

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved