×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    37

    Simple Socket(Client) Problem

    hi there,

    I've got a problem with the following code :

    Code:
    			RSocket *iSocket = new (ELeave) RSocket();
    			RSocketServ iSocketServ;
    			TInetAddr iAddress;
    			TRequestStatus aStatus;
    			iAddress.SetPort(80);
    			iAddress.SetAddress(INET_ADDR(38, 117, 64, 4));
    
    			TInt iReturn;
    			iReturn = iSocketServ.Connect();
    			iReturn = iSocket->Open(iSocketServ, KAfInet, KSockStream,
    					KProtocolInetTcp);
    			if (!iReturn)
    				iSocket->Connect(iAddress, aStatus);
    
    			User::WaitForRequest(aStatus);
    			if (aStatus != KErrNone)
    				{
    				 // ALWAYS GOES HERE :(
    				}
    			else
    				{
    
    				HBufC8* bufSock = HBufC8::NewL(30);
    				bufSock->Des().Append(_L8("GET / HTTP/1.0\r\n\r\n"));
    				iSocket->Write(*bufSock, aStatus);
    				User::WaitForRequest(aStatus);
    
    				TBuf8<100> buf;
    				iSocket->Recv(buf, 0, aStatus);
    				User::WaitForRequest(aStatus);
    				}
    			iSocket->Close();
    			}
    it tries to connect to a http server, but never get connected and always returns an error and goes to the mentioned red line...

    any help would be highly appreciated...

  2. #2
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,086

    Re: Simple Socket(Client) Problem

    well you can get that error:

    TInt error = aStatus.Int();

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    37

    Re: Simple Socket(Client) Problem

    Quote Originally Posted by vineet.jain View Post
    well you can get that error:

    TInt error = aStatus.Int();
    Tanks for your prompt reply,

    the error code is -46

  4. #4
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,086

    Re: Simple Socket(Client) Problem

    well that means KErrPermissionDenied.I think the RSocket:Connect() is capability dependent.

  5. #5
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: Simple Socket(Client) Problem

    then you are propably missing network capability..

  6. #6
    Registered User
    Join Date
    Oct 2010
    Posts
    37

    Re: Simple Socket(Client) Problem

    thanks for your prompt replies,

    well, what exactly does it mean?

  7. #7
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,086

    Re: Simple Socket(Client) Problem

    well that means you need to add capability in your mmp file. CAPABILITY keyword in written in you mmp file, you need to add NetworkServices capability in that section.

  8. #8
    Registered User
    Join Date
    Oct 2010
    Posts
    37

    Re: Simple Socket(Client) Problem

    Quote Originally Posted by vineet.jain View Post
    well that means you need to add capability in your mmp file. CAPABILITY keyword in written in you mmp file, you need to add NetworkServices capability in that section.
    it works ...
    THANKS MATE ;D

  9. #9
    Registered User
    Join Date
    Oct 2010
    Posts
    37

    Re: Simple Socket(Client) Problem

    sorry if I bother you mates but I've got another problem

    I have two cellphone(N97) which obtain two static IP on a 3G network, one as client(with the ip address of 192, 168, 100, 15) and another as server(with the ip address of 192, 168, 100, 20)...and I am trying to connect from the client to the server on the port#2222(or whatever port...).

    In the client side I put the following code :

    Code:
    			RSocket *iSocket = new (ELeave) RSocket();
    			RSocketServ iSocketServ;
    			TInetAddr iAddress;
    			TRequestStatus aStatus;
    			iAddress.SetPort(2222);
    			iAddress.SetAddress(INET_ADDR(192, 168, 100, 20));
    			
    			TInt iReturn;
    			iReturn = iSocketServ.Connect();
    			iReturn = iSocket->Open(iSocketServ, KAfInet, KSockStream,
    					KProtocolInetTcp);
    			if (!iReturn)
    				iSocket->Connect(iAddress, aStatus);
    			TInt error;
    			User::WaitForRequest(aStatus);
    			if (aStatus != KErrNone)
    				{
    					error = aStatus.Int(); 
    				}
    			else
    				{
    
    				HBufC8* bufSock = HBufC8::NewL(30);
    				bufSock->Des().Append(_L8("Simple Command\r\n\r\n"));
    				iSocket->Write(*bufSock, aStatus);
    				User::WaitForRequest(aStatus);
    
    				TBuf8<100> buf;
    				iSocket->Recv(buf, 0, aStatus);
    				User::WaitForRequest(aStatus);
    				}
    			iSocket->Close();
    and the server side I've got the following code :

    Code:
    			RSocket *iSocket = new (ELeave) RSocket();
    
    			RSocketServ iSocketServ;
    			TRequestStatus aStatus;
    			TInt iReturn;
    			iReturn = iSocketServ.Connect();
    			iReturn = iSocket->Open(iSocketServ, KAfInet, KSockStream,
    					KProtocolInetTcp);
    
    			TInetAddr address(KInetAddrAny, 2222);
    			iSocket->Bind(address);
    			iSocket->Listen(5);
    
    
    			RSocket acceptSock;
    			User::LeaveIfError(acceptSock.Open(iSocketServ));
    
    			iSocket->Accept(acceptSock, aStatus);
    
    			User::WaitForRequest(aStatus); 
    			if (aStatus != KErrNone)
    				{
    				// do something about the error
    				}
    			else
    				{
    
    				TBuf8<100> buf;
    				iSocket->Recv(buf, 0, aStatus);
    				User::WaitForRequest(aStatus);
    
    				HBufC8* bufSock = HBufC8::NewL(30);
    				bufSock->Des().Append(_L("Test Reply Command\r\n\r\n"));
    				iSocket->Write(*bufSock, aStatus);
    				User::WaitForRequest(aStatus);
    
    				iSocket->SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);
    				iSocket->Close();
    
    				}
    when I debug the two part they stock on the red lines...

    any help would be so appreciated...

  10. #10
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,086

    Re: Simple Socket(Client) Problem

    User::WaitForRequest(aStatus); should generally be avoided.Use SetActive() in place of it & also implement the RunL() method which would be called whenever the async request gets completed.(iSocket->Accept(acceptSock, aStatus is an async. request).

  11. #11
    Registered User
    Join Date
    Nov 2010
    Posts
    9

    Re: Simple Socket(Client) Problem

    I want to connect to a server that needs a username and a password in order to connect. How can i send in the Username and Password values. Thanks
    David

  12. #12
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: Simple Socket(Client) Problem

    firstly you would need to know what kind of prorocol is used in there, and if you insist using sockets, then you would really need to do all buffers there by yourself. anyway, I would suppose you should just stick on the own threads you have made on the topic, and where you actually specify that you want to do FTP.

  13. #13
    Registered User
    Join Date
    Mar 2011
    Posts
    2

    Re: Simple Socket(Client) Problem

    Can you tell me that which SDK are you using? B'coz i have same code, it debugg successfully but not connecting to ip address can u help me please?

  14. #14
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,750

    Re: Simple Socket(Client) Problem

    RSocket API works with anything, the SDK does not matter. Do you get a KErrCouldNotConnect or something?

    You may want to check if the given emulator/device has access to the network (it can be tested with the built-in browser for example).

  15. #15
    Registered User
    Join Date
    Mar 2011
    Posts
    2

    Re: Simple Socket(Client) Problem

    Quote Originally Posted by wizard_hu_ View Post
    RSocket API works with anything, the SDK does not matter. Do you get a KErrCouldNotConnect or something?

    You may want to check if the given emulator/device has access to the network (it can be tested with the built-in browser for example).
    can you tell me whole process to check that emulator is accessing network or not?

Similar Threads

  1. Socket Server Client Problem
    By nyerunkar in forum Mobile Java Networking & Messaging & Security
    Replies: 4
    Last Post: 2010-11-23, 16:40
  2. Problem in Sending data using Symbian Socket client to the PC based socket server
    By pankaj.dubey in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2008-02-26, 15:09
  3. Problem with Java Client Socket with C# Server
    By scottleaw in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2007-09-25, 06:56
  4. Replies: 1
    Last Post: 2007-09-25, 03:42
  5. Simple Server/Client Socket program
    By mottaisami in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2006-09-08, 21:58

Posting Permissions

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