|
|
User login
Feeds |
IP address=0 when using RSockets and RConnection???
|
|||||
| Wed, 2007-05-23 09:58 | |
|
Hi,
I am trying to write a server-client socket app that facilitates comm between two phones. I am having a problem with the server app when it tries to initiate itself. I reached the stage where the IAP connections list is displayed where i managed to select an approperiate conneection (T-Mobile). The app waits to get the RConenction::Start() returns KErrNone in iStatus. Once that completed and no error is returned i process the state in RunL() according to the state i set after Start() (which is iState=EStartConnecting). Till here everything is going well without any troubles. But when i am in that block of RunL and try to get the IP address assigned for the "server" phone i always get 0.0.0.0. Why is that? i checked if the block in RunL would be entered if i choose an unproper IAP (say orange) but it does not. I am using the following code sequence (not the exact code): // in header RSocketServ iSockServ; RConnection iConn; RSocket iSocket; RSocket iServiceSock; TInt iState; ... // in ConstructL User::LeavIfError(iSockServ.Connect()); User::LeavIfError(conn.Open(iSockServ)); User::LeaveIfError(conn.Start(iStatus)); // get the IAP list to select from iState = EStartConnecting; SetActive(); ... // in RunL if(iState == EStartConnecting && iStatus == KErrNone) { User::LeaveIfErro(iSocket.Open(iSockServ, KAfInet, KSockStream, KProtocolInetTcp, iConn)); TInetAddr addr; addr.SetPort(3100); iSocket.LocalName(addr); // to put the IP address in addr // Display the Ip address here (via addr.Address()) and i get 0.0.0.0 User::LeaveIfError(iSocket.Bind(addr)); User::LeaveIfError(iSocket.Listen(20)); iServiceSock.Open(iSockServ); iServiceSock.Accept(iSocket, iStatus); iState = EConnecting; SetActive(); } best AF |
|
Forum posts: 100
After accept, the LocalName of the connected socket (iServiceSocket) does have the actual IP-address (depending on which address was used to connect).
Your code is confusing the "iSocket" and "iServiceSocket", the
should be
Forum posts: 123
yes u r right about the typo thr it is my mistake. it should be
iSocket.Accept(iServiceSocket, iStatus);
How could a blank socket hold the address of the connection? i though that this socket is used only to take over the communication with a remote peer from the listening one when a connection is accepted. How come now it holds the IP address?
even i tried to modify my code to add that bit of retreiving the iServiceSock address after accept but the app is crashing.
cheers
AF
Forum posts: 100
When your Accept completes (after someone connects in), the blank socket becomes a normal connected TCP socket, and it has all the address and port information filled in.
Forum posts: 123
so there is no way to retreive the address of the server before connecting?
How would clients connect to this server if they do not know its address? The server will wait for clients to connect to it in order to aquire its address and the clients need this address to connect to the server... that is a dead lock!!!
am confused now
Forum posts: 2025
Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant
Forum posts: 123
can you be please more illuborative?
AF
Forum posts: 100
Well, almost: Nobody knows the address until the IAP connection has been opened and up.
The listening server socket does not need to know own address, it's bound to NONE, which means it accepts incoming connections to loopback addresses (Ipv4 or IPv6), or any addresses (ipv4 or ipv6) of any IAPs you choose to activate.
This is totally independent issue. Once you have activated some IAP, the phone will have one or more addresses.
There are ways to find out addresses (see the sticky articles on this board). You can scan the addresses and just print them out and then use them in the clients connecting to the phone's server. (Assuming there are no evil NAT's in between by the service providers).
Alternate way is just use KSoInetQueryByDstAddr socket option. In the parameter TSoInetIfQuery, fill in the iDstAddr with some global IPv4 or IPv6 address and issue the socket option. In return, the iSrcAddr should be filled with proper local address that could be used in communicating with the address given in iDstAddr. If getoption returns error or iSrcAddr is NONE, then there is no suitable address available (no suitable IAP's is up).
Check the Symbian docs for details of TSoInetIfQuery and you can also see examples of its use in some posts, that use the interface scanning alternative in finding all addresses.