×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Regular Contributor
    Join Date
    Jan 2005
    Posts
    154

    Failed to connect a TCP client app with a server

    Hi all,

    I have been struggling with having this working for a long time now I have failed to connect a socket client app to a socket server app bith running on different phones (and using different SIM cards: T-Mobile and O2). The thing is i managed to get the IP address allocated for the server. And everytime i try to connect the client via that IP the connection fails (ie does not initiate)

    I have the server implemented as follows:


    void CSocketEngine::ConstructL()
    {
    CActiveScheduler::Add(this);

    // If in Idle state
    if(iState == EIdle)
    {
    // Connect the socket
    TInt err = iSocketServ.Connect();
    if( err != KErrNone && err != KErrAlreadyExists)
    User::Leave(err);

    // get the number of protocols supported (bluetooth, irda, tcp...)
    TUint protNb;
    err = iSocketServ.NumProtocols(protNb);
    User::LeaveIfError(err);

    // to view the IAP dialog and select one from it
    User::LeaveIfError(iConnection.Open(iSocketServ));
    iConnection.Start(iStatus);
    iState = EStartConnecting;
    SetActive();
    }
    }

    void CSocketEngine::RunL()
    {
    if( iState == EStartConnecting && iStatus == KErrNone)
    {
    TInt err;
    // now open the socket on the socker server session created with the IAP interface connection
    err = iSocket.Open( iSocketServ,
    KAfInet,
    KSockStream,
    KProtocolInetTcp,
    iConnection );
    if(err != KErrNone)
    User::LeaveIfError(err);

    TInetAddr addr;
    // get teh IP address allocated after RConnection::Start()
    // this address will be displayed on screen and dictated to the client
    GetIp(addr);

    // Bind the socket to the address and a port
    iInetAddr.SetPort(0x02);
    iInetAddr.SetAddress(addr.Address());
    iSocket.Bind(iInetAddr);

    // make the socket listening (parameter specifies the size of the quoue)
    iSocket.Listen(1);

    // open another socket to service any connection request as the listening
    // socket must be free always to listen for incomming connection requests.
    err = iServiceSocket.Open(iSocketServ);
    if(err != KErrNone)
    User::LeaveIfError(err);

    // Accept the first connection. This is an asynchronous call.
    iSocket.Accept(iServiceSocket, iStatus);
    iState = EAccepting;
    SetActive();
    }
    else if(iState == EAccepting && iStatus == KErrNone)
    {
    /***************************************/
    // THIS PART HERE IS NOT REACHED EVER
    /***************************************/
    CAknInformationNote *note = new (ELeave) CAknInformationNote();
    CleanupStack::PushL(note);
    note->ExecuteLD(_L("Recieved"));
    CleanupStack::Pop();
    }
    }

    TInt CSocketEngine::GetIp(TInetAddr &aAddr)
    {
    RSocket socket;
    User::LeaveIfError(socket.Open( iSocketServ,
    KAfInet,
    KSockStream,
    KProtocolInetTcp) );

    TUint32 iapId = 0;
    User::LeaveIfError(iConnection.GetIntSetting(_L("IAP\\Id"), iapId));

    TSoInetInterfaceInfo ifinfo;
    TPckg<TSoInetInterfaceInfo> ifinfopkg(ifinfo);

    TSoInetIfQuery ifquery;
    TPckg<TSoInetIfQuery> ifquerypkg(ifquery);

    User::LeaveIfError(socket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl));
    while(socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, ifinfopkg) == KErrNone)
    {
    ifquery.iName = ifinfo.iName;
    TInt err = socket.GetOpt(KSoInetIfQueryByName, KSolInetIfQuery, ifquerypkg);
    if( err == KErrNone && ifquery.iZone[1] == iapId)
    {
    if(ifinfo.iAddress.Address() >0)
    {
    aAddr = ifinfo.iAddress;
    socket.Close();
    return err;
    }
    }
    else if(err != KErrNone)
    {
    socket.Close();
    return err;
    }
    } // while
    socket.Close();
    return KErrNotFound;
    }



    The client is implemented as follows:


    void CSocketEngine_C::ConnectClient(TDes& aIp) // The IP address of the server
    {
    // If in Idle state
    if(iState == EIdle)
    {
    // Connect the socket
    TInt err = iSocketServ.Connect();
    if( err != KErrNone && err != KErrAlreadyExists)
    User::Leave(err);

    // get the number of protocols supported (bluetooth, irda, tcp...)
    TUint protNb;
    err = iSocketServ.NumProtocols(protNb);
    User::LeaveIfError(err);

    // Set the address of the server app to connect to
    TInetAddr temp;
    temp.Input(aIp);
    iInetAddr.SetAddress(temp.Address());
    iInetAddr.SetPort(0x02);

    // now open the socket on the socker server session created
    err = iSocket.Open( iSocketServ,
    KAfInet,
    KSockStream,
    KProtocolInetTcp);
    if(err != KErrNone)
    User::LeaveIfError(err);

    iSocket.Connect(iInetAddr, iStatus);
    iState = EConnecting;
    SetActive();
    }
    }

    void CSocketEngine_C::RunL()
    {
    if(iState == EConnecting)
    {
    /***********************************/
    // This part is never reached
    /***********************************/
    CAknInformationNote *note = new (ELeave) CAknInformationNote();
    CleanupStack::PushL(note);
    note->ExecuteLD(_L("Connected"));
    CleanupStack::Pop();
    }
    }

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,674

    Re: Failed to connect a TCP client app with a server

    Many mobile operators simply do not allow you to accept connections (neither originating from the same network nor originating from somewhere else).
    Since you are using S60 3rd edition (as I remember), you can still test your app via using WLAN (if you have no infrastructure WLAN, but your phones do support WLAN, note that you can create an Ad-hoc WLAN network too: create a new access point, select WLAN, set the same name on both devices, and select Ad-hoc mode).

  3. #3
    Regular Contributor
    Join Date
    Jan 2005
    Posts
    154

    Re: Failed to connect a TCP client app with a server

    Hi,

    thanx for your reply. I am using S60 yes, but not 3rd (i may later). regardign what you said, in that case no network app will be allowed on mobile phones!! i rememebr i was working on a Java app that had to communicate with a backend server (PC not phone) where it had to send and receive data. that app was tested on all Uk operators and was working. How could it be now that this app (the one i am working on) is not allowed to initiate connection?? I don know if that java app was using sockets (i doubt it) but i know that it used HTTP for communication. Is there any other protocol that can be used to achieve the client talking to the server and the server responding in return?

    and one more thing, is my code above correct? is there anything missing? or should it be fine?

    cheers
    AF

  4. #4
    Regular Contributor
    Join Date
    May 2006
    Location
    Hyderabad,India
    Posts
    89

    Re: Failed to connect a TCP client app with a server

    have you tested this on sim? you can test with telnet on desktop.
    http://www.midpjni.com/ you can get tcp server code which will wait for client to connect.
    its for some other purpose but it will work for you as you need stable server code.

    Regards,
    Sheshu Kumar Inguva.

  5. #5
    Regular Contributor
    Join Date
    Jan 2005
    Posts
    154

    Re: Failed to connect a TCP client app with a server

    thanx inguvaseshu for your reply
    i did try the code with sims (one O2 and one T-Mobile).
    what do you mean by stable server?
    i will try the apps provided in your link.

    thanx again
    AF

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,674

    Re: Failed to connect a TCP client app with a server

    Quote Originally Posted by abolfoooud
    regardign what you said, in that case no network app will be allowed on mobile phones!!
    Not exactly. I have said that about accepting inbound connections, thus acting as a server. Outgoing (client) connections should be usually ok.
    i rememebr i was working on a Java app that had to communicate with a backend server (PC not phone) where it had to send and receive data. that app was tested on all Uk operators and was working.
    Yes, because the mobile was the client, and the PC was the server. Operators like this situation.
    How could it be now that this app (the one i am working on) is not allowed to initiate connection??
    A part of your code is accepting a connection, that is the part that will probably do not work with every possible operators.
    I don know if that java app was using sockets (i doubt it) but i know that it used HTTP for communication. Is there any other protocol that can be used to achieve the client talking to the server and the server responding in return?
    Java is not miracle, it also uses sockets for communication. Although it is also possible that an operator enables HTTP connections, but disables arbitrary data connections.
    and one more thing, is my code above correct? is there anything missing? or should it be fine?
    The code seems to be fine.

    I guess Inguvaseshu means on 'sim' the simulator (although it is usually called emulator) not a SIM card.

  7. #7
    Regular Contributor
    Join Date
    Jan 2005
    Posts
    154

    Re: Failed to connect a TCP client app with a server

    Hi wizard_hu_

    now i have the full image clear.... I HATE mobile operators :S
    you mentioned that inbound connection is not allowed. is this the case also for clients if they want to receive data via TCP? or is this limited to the server characteristic only?

    Also, what should i use to achieve several phones communicating with a server (whther running on a phone or on a PC) whith data being exchanged in between? Shall i write a WinSock app and have it on a PC running with real IP abd that would solve it? Will i face any difficulties or operator limitations in that scenario? Is there any suggestion you can give me?

    thanx
    AF

  8. #8
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,674

    Re: Failed to connect a TCP client app with a server

    Quote Originally Posted by abolfoooud
    you mentioned that inbound connection is not allowed. is this the case also for clients if they want to receive data via TCP? or is this limited to the server characteristic only?
    TCP is bi-directional by its nature (flow control, etc. require that), the limitation is about being a server. An e-mail client or a Web-browser need bi-directional communication, but both of them are clients.
    Also, what should i use to achieve several phones communicating with a server (whther running on a phone or on a PC) whith data being exchanged in between? Shall i write a WinSock app and have it on a PC running with real IP abd that would solve it? Will i face any difficulties or operator limitations in that scenario? Is there any suggestion you can give me?
    Yes, it is a viable way: write a simple tunneling server for the PC, accept two TCP connections, and forward data between them. "Traditional" WinSock is OK for that, however it is faster to use Java or .Net.

  9. #9
    Regular Contributor
    Join Date
    Jan 2005
    Posts
    154

    Re: Failed to connect a TCP client app with a server

    I just managed to have the application running!!!!!
    the problem was on using 2 different SIM cards. I used two T-Mobile sims and now it is working!!! i received the message on the server and on the client

    the mis concesption i had was that the IPs allocated to the phones are real ones (but it turned out to be virtual)!!! that misunderstanding caused all the trouble. i was trying to connect one IP from one local network (T-Mobile) to another one on a different local network (O2) without sorting the gateway boundary issues. Now, whilst i am within the same network IPs can find themselves and communicate freely without caring of the gateway

    so, those who are having the trouble. get yourself similar sims. if you require more generic approach, then use what wizard_h_ has recommended: "write a simple tunneling server for the PC, accept two TCP connections, and forward data between them".

    enjoy the code cracking now
    AF

  10. #10
    Registered User
    Join Date
    Feb 2005
    Posts
    13

    Re: Failed to connect a TCP client app with a server

    I am also facing same type of problem.
    Can you look up the below mentioned link and review your comments.
    http://discussion.forum.nokia.com/fo...d.php?t=116398

    Thanks.

  11. #11
    Registered User
    Join Date
    Jul 2008
    Location
    England
    Posts
    48

    Re: Failed to connect a TCP client app with a server

    Hi all,

    Ok my turn to help now... iv'e recived some help so far, but i can shed some light on why this works as it does.

    (I knew my experience as a GSM networks engineer would come in handy someday ;-) )

    Anyway...


    When your phone is connected to a GSM network, it's not directly connected to the PSTN or any other public IP network, instead it's connected into the operators private cloud.

    The first thing it hits is the BTS (Dont worry, i'll list the ancronyms at the end) from the BTS, it connects to the BSC, and then from there to the MSC. By this point, the different data streams have been seperated out, and if it's a voice communication, then the voice signal will have been transcoded and turned into TCP data, a data connection however will have been routed to an SGSN.

    Within the GSM operator cloud it's very unlikley that TCP is being used, common high speed links such as ATM & X25 are otften used, but there are many varying ones, often very proprietary.

    The bottom line is that, the device and it's software might understand TCP/IP from an app perspective but you can bet your bottom dollar that there is no TCP/IP link to them from the network.

    This is where the SGSN comes into play.

    The SGSN takes the inbound streams and allocates an IP based connection for the device, it acts kind of like your home broadband router, in that any packets hitting that IP get routed accross the operators network to that handset, in a similar fasion to someone connecting to your router and you routing it to the appropriate PC/Server.

    That however is not the end of the story, the SGSN on it's own is only a geographic singleton, that is to say that they ONLY connect within the operators network, and each SGSN will be specific to a given area. To go outside the network you then have a GGSN, the seperate SGSN's talk to this and this then has links via cable/satalite/PSTN etc etc to the public networks.

    The IP address you see allocated to a handset, is an IP address on an interface on the connected GGSN not on the handset as many people believe, as for the IP address allocated on the handset, then what any app may report on the handset is simply a fake one that the network understands, and is generally allocated by the SGSN.

    This is why 2 devices on the same operators network can see each other, beacase they both connect into SGSN's, and these SGSN's keep track of allocated addresses in whatever format the handset connection makes, and just like the DNS system, they allow routing within their home network, from the outside however your most likely to see the GGSN allocate either an address from a registered pool of dynamic addresses owned by the operator, or a private 10.1.1.X/192.168.xx.xx address, which beacuse it's private use cannot be routed to without first establishing a connection itself.

    So... the question i now hear you asking is, so does that mean it's not at all possible to run any kind of server service on a mobile device? what about mobile telemetry for example?

    Well, this is where your Access points come into play... you know those things you have to configure into your handset... such as "o2.wap" or "t-mobile.mccn.gprs", as consumers you only get to know about the public access points, however the operator has the capabilty to define and manage any AP within their network, and typicly there's a couple of 100 or so of them.

    Companies with a special need can apply for a private AP, this AP is presented by the client communicating at the GGSN end on a given IP, the GGSN then knows which SGSN to route directly to, and the SGSN knows which terminal to route to. Access points are kind of like having your own private DNS server, behind your router, joe public see's "www.mydomain.com" but behind the scenes you might have "mediaserver.mynetwork.net" and "bigcomputer.mynetwork.net" , your router knows how to reach them, but joe public doesn't :-)

    The GGSN however knows exactly what to do with a given access point, and more appropriately what it is/is not allowed to connect to, this is why you often have a seperate WAP and GPRS AP on your phone, beacuse your WAP AP will only allow you to connect to the operators wap services (Which are often delivered within their cloud), where as GPRS AP will often be routed outbound to public networks, and not allowed to touch internal services. If you have the right AP's coming inbound, you can often connect to all sorts of other networks or services that are available via a given operator or it's partners.


    Phew...

    Hope that provides so techie brain fodder for some of you...

    oh and as promised...

    BTS = Base transciever station (A cell mast)
    BSC = Base station controler (Controling Cell tower, and main gateway to network)
    MSC = Mobile switching centre (A digital exchange)
    SGSN = Serving GPRS Support node (Local Mobile TCP support platform)
    GGSN = Gateway GPRS Support node (Gateway Mobile TCP support platform)
    PSTN = Public switched telephone network

    Reagrds

    Shawty
    Last edited by shawty; 2008-08-24 at 07:57.

Similar Threads

  1. S60 2nd to 3rd/ PlatformSecurity / Capabilities
    By jarkoos in forum Symbian Signed Support, Application Packaging and Distribution and Security
    Replies: 4
    Last Post: 2007-04-14, 14:08
  2. Replies: 6
    Last Post: 2007-01-09, 06:04
  3. client server connection problem
    By jeff4yee in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2006-09-28, 11:11
  4. Client and Server Program
    By Ravikumar in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2006-09-18, 14:41
  5. http error to connect to Activ server
    By supriya_nandi in forum WAP Servers
    Replies: 2
    Last Post: 2002-11-06, 09:32

Posting Permissions

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