×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    24

    In UDP client/server Application get system Error -6.

    Hi

    I read lots of thread and make two UDP client and server application and try to send message from client to server(for read message), show my code, and please help me that where i ma going to wrong?

    In both application i set port = 2000, and
    In client application set IP: TInetAddr addr(KInetAddrLoop, aPort);
    In Server application set IP: TInetAddr addr(KInetAddrAny, aPort);

    I am doing testing following way:
    I run Client application in S60 3rd FP1 simulator and
    Server Application in S60 3rd FP2 simulator.

    Client Application
    Code:
    /*
     * UDPClient.cpp
     *
     *  Created on: Nov 12, 2013
     *      Author: Admin
     */
    
    #include "UDPClient.h"
    #include "FileLoggerDLL.h"
    
    CUdpClient* CUdpClient::NewLC(TInt aPort)
    	{
    	CUdpClient *self = new (ELeave) CUdpClient();
    	CleanupStack::PushL(self);
    	self->ConstructL(aPort);
    	return self;
    	}
    
    CUdpClient* CUdpClient::NewL(TInt aPort)
    	{
    	CUdpClient *self = CUdpClient::NewLC(aPort);
    	CleanupStack::Pop();
    	return self;
    	}
    
    CUdpClient::CUdpClient(): CActive(EPriorityStandard)
    	{
    	// No implementation required
    	}
    
    void CUdpClient::ConstructL(TInt aPort)
    	{
    	CFileLoggerDLL::Write(_L("In ConstructL"));
    	CActiveScheduler::Add(this);
    	
    	User::LeaveIfError( iServ.Connect() ); 	
    	CFileLoggerDLL::Write(_L("In Connect"));
    	
    	User::LeaveIfError( iSock.Open(iServ, KAfInet, KSockDatagram, KProtocolInetUdp) );
    	CFileLoggerDLL::Write(_L("In Open"));
    	
    	//TInetAddr addr(KInetAddrNone, aPort);
    	TInetAddr addr(KInetAddrLoop, aPort);
    	iFrom = addr;
    	User::LeaveIfError( iSock.Bind(addr) );
    	
    	//CFileLoggerDLL::Write(_L("Do Read"));
    	DoSend();
    	}
    
    CUdpClient::~CUdpClient()
    	{
    	Cancel();
    	iSock.Close();
    	iServ.Close();
    	CFileLoggerDLL::Close();
    	}
    
    void CUdpClient::DoSend()
    	{
    	CFileLoggerDLL::Write(_L("In Send"));
    	_LIT8(KSendData, "Send from Client");
    	iSendBuffer.Copy(KSendData);
    	iSock.SendTo(iSendBuffer,iFrom,0,iStatus);
    	SetActive();
    	
    	}
    
    void CUdpClient::RunL()
    	{
    	CFileLoggerDLL::Write(_L("RunL"));
    	if (iStatus == KErrNone)
    		{
    		CFileLoggerDLL::Write(iSendBuffer);
    		//iSock.Write( _L("Received OK FROM Client"), iStatus );
    		// Do something with received data
    		}
    	CFileLoggerDLL::Write(_L("Do Send"));
    	DoSend();
    	}
    
    void CUdpClient::DoCancel()
    	{
    	iSock.CancelRecv();
    	}

    server Application File
    Code:
    /*
     * UDPServer.cpp
     *
     *  Created on: Nov 12, 2013
     *      Author: Admin
     */
    
    #include "UDPServer.h"
    #include "FileLoggerDLL.h"
    
    CUdpServer* CUdpServer::NewLC(TInt aPort)
    	{
    	CUdpServer *self = new (ELeave) CUdpServer();
    	CleanupStack::PushL(self);
    	self->ConstructL(aPort);
    	return self;
    	}
    
    CUdpServer* CUdpServer::NewL(TInt aPort)
    	{
    	CUdpServer *self = CUdpServer::NewLC(aPort);
    	CleanupStack::Pop();
    	return self;
    	}
    
    CUdpServer::CUdpServer(): CActive(EPriorityStandard)
    	{
    	// No implementation required
    	}
    
    void CUdpServer::ConstructL(TInt aPort)
    	{
    	CFileLoggerDLL::Write(_L("In ConstructL"));
    	CActiveScheduler::Add(this);
    	
    	User::LeaveIfError( iServ.Connect() ); 	
    	CFileLoggerDLL::Write(_L("In Connect"));
    	
    	User::LeaveIfError( iSock.Open(iServ, KAfInet, KSockDatagram, KProtocolInetUdp) );
    	CFileLoggerDLL::Write(_L("In Open"));
    	
    	//TInetAddr addr(KInetAddrNone, aPort);
    	//TInetAddr addr(KInetAddrLoop, aPort);
    	TInetAddr addr(KInetAddrAny, aPort);
    	iFrom = addr;
    	User::LeaveIfError( iSock.Bind(addr) );
    	
    	CFileLoggerDLL::Write(_L("Do Read"));
    	DoRead();
    	}
    
    CUdpServer::~CUdpServer()
    	{
    	Cancel();
    	iSock.Close();
    	iServ.Close();
    	CFileLoggerDLL::Close();
    	}
    
    void CUdpServer::DoRead()
    	{
    	CFileLoggerDLL::Write(_L("In Reading"));
    	iSock.RecvFrom(iBuffer, iFrom, 0, iStatus);
    	
    	SetActive();
    	}
    
    void CUdpServer::RunL()
    	{
    	CFileLoggerDLL::Write(_L("RunL"));
    	if (iStatus == KErrNone)
    		{
    		CFileLoggerDLL::Write(iBuffer);
    		//iSock.Write( _L("Received OK FROM Client"), iStatus );
    		// Do something with received data
    		}
    	CFileLoggerDLL::Write(_L("Do Read"));
    	DoRead();
    	}
    
    void CUdpServer::DoCancel()
    	{
    	iSock.CancelRecv();
    	}

  2. #2
    Registered User
    Join Date
    Sep 2013
    Posts
    24

    Re: In UDP client/server Application get system Error -6.

    Hi

    Please please help me in my client / server UDP programming.

  3. #3
    Nokia Developer Expert
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,142

    Re: In UDP client/server Application get system Error -6.

    error code reference is in wiki: http://developer.nokia.com/Community...OS_Error_Codes

    basically -6 comes often when you use invalid arguments, thus you should first pinpoint the actual function call which leaves with this error, and then check what kind of values you are giving into it.

  4. #4
    Registered User
    Join Date
    Sep 2013
    Posts
    24

    Re: In UDP client/server Application get system Error -6.

    Hi

    I remove User::LeaveIfError( iSock.Bind(addr) ); line from SERVER application now I am not getting any error, but still I not getting receive message from client.

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

    Re: In UDP client/server Application get system Error -6.

    you propably should not go removing lines which are required, instead you should figure out what is going wrong in the line, and to fix it.

    Also when you get the runL called, do check what the iStatus is, and whether it is indicating any errors.

  6. #6
    Registered User
    Join Date
    Sep 2013
    Posts
    24

    Re: In UDP client/server Application get system Error -6.

    Hi

    I make UDP Server application using OpenC console exe and able to receive data successfully and make .3gp file.

    But now problem is how i play video simultaneously in GUI Application. My Actual process flow I describe here: http://developer.nokia.com/Community...erver?p=929416

    So please let me know that I am going on right/wrong way? please

    My Code is:
    #include <sys/types.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <string.h>
    #include <netdb.h>
    #include <stdio.h>

    //#include "FileLoggerDLL.h"

    void error(const char *msg)
    {
    perror(msg);
    exit(0);
    }

    //int main(int argc, char *argv[])
    int main(void)
    {

    int sock, length, n, c;
    socklen_t fromlen;
    struct sockaddr_in server;
    struct sockaddr_in from;
    char buf[1024];
    FILE *udp ;
    /* printf("No. of arg = %d\n",argc);
    printf("First is = %s\n", argv[0]);
    printf("Second is = %s\n", argv[1]);
    printf("Hello Open C!\n");
    printf("Press a character to Execute!");

    c = getchar();

    if (argc < 2) {
    fprintf(stderr, "ERROR, no port provided\n");
    exit(0);
    }*/

    printf("Hello Open C!\n");
    printf("Press a character to Execute!");

    c = getchar();

    sock=socket(AF_INET, SOCK_DGRAM, 0);
    if (sock < 0) error("Opening socket");
    length = sizeof(server);
    bzero(&server,length);
    server.sin_family=AF_INET;
    server.sin_addr.s_addr=INADDR_ANY;
    //server.sin_port=htons(atoi(argv[1]));
    server.sin_port=5000;
    if (bind(sock,(struct sockaddr *)&server,length)<0)
    error("binding");
    fromlen = sizeof(struct sockaddr_in);

    udp = fopen("c:\\udpData.3gp","w");

    while (1) {
    n = recvfrom(sock,buf,1024,0,(struct sockaddr *)&from,&fromlen);
    if (n < 0) error("recvfrom");
    write(1,"Received a datagram: ",21);
    write(1,buf,n);

    //memset(buf,0,sizeof(buf));
    fwrite(buf, n, 1, udp);
    fflush(udp);

    n = sendto(sock,"Got your message\n",17,0,(struct sockaddr *)&from,fromlen);
    if (n < 0) error("sendto");
    }

    if(udp) {
    fclose(udp);
    udp = 0;
    }
    return 0;
    }

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,567

    Re: In UDP client/server Application get system Error -6.

    Probably the problem with the Symbian C++ code was that you were binding to KInetAddrLoop.
    In the C code you are binding to INADDR_ANY. Symbian C++ also has that, KInetAddrAny.

  8. #8
    Registered User
    Join Date
    Sep 2013
    Posts
    24

    Re: In UDP client/server Application get system Error -6.

    Quote Originally Posted by wizard_hu_ View Post
    Probably the problem with the Symbian C++ code was that you were binding to KInetAddrLoop.
    In the C code you are binding to INADDR_ANY. Symbian C++ also has that, KInetAddrAny.
    Hi

    I tried with KInetAddrAny but still same problem, No ask about access point also and do not call RunL function.
    I print logs in file, File writes"In Reading" log after nothing.

    OpenC Code ask about access point for doing connetion, but gui do not ask, What i do for that?



    void CUdpServer:oRead()
    {
    CFileLoggerDLL::Write(_L("In Reading"));
    iSock.RecvFrom(iBuffer, iFrom, 0, iStatus);

    SetActive();
    }

    void CUdpServer::RunL()
    {
    CFileLoggerDLL::Write(_L("RunL"));
    if (iStatus == KErrNone)
    {
    CFileLoggerDLL::Write(iBuffer);
    //iSock.Write( _L("Received OK FROM Client"), iStatus );
    // Do something with received data
    }
    CFileLoggerDLL::Write(_L("Do Read"));
    DoRead();
    }

  9. #9
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,567

    Re: In UDP client/server Application get system Error -6.

    That is normal, in server code by default you simply bind to available interfaces, and loopback is always available.
    RConnection::Start is the thing you want to check for starting up an access point. Then you should use the RSocket::Open variant accepting an RConnection argument.

  10. #10
    Registered User
    Join Date
    Sep 2013
    Posts
    24

    Re: In UDP client/server Application get system Error -6.

    Thanks wizard_hu_

    I Read your post no 7 from: http://developer.nokia.com/Community...0-18f9c13acbe8

    it's very useful for me implement UDP client-server application in GUI app, thanks again.

  11. #11
    Registered User
    Join Date
    Sep 2013
    Posts
    24

    Re: In UDP client/server Application get system Error -6.

    Hi

    If I want to write article or post UDP Client/Server Application code than am I able to do this for other developers?

Similar Threads

  1. Selling client / server application
    By walkl in forum [Closed] Publishing to Nokia Store
    Replies: 1
    Last Post: 2010-06-10, 14:32
  2. How to Test client-server application In the local server.
    By mrrajesh_1982 in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2006-11-09, 00:25
  3. How to run client-server Application on emulator..
    By sumanthgwn in forum Mobile Java Networking & Messaging & Security
    Replies: 6
    Last Post: 2006-09-21, 06:27
  4. error on client server framework
    By ceehira in forum Symbian C++
    Replies: 0
    Last Post: 2006-07-18, 10:52
  5. Build Client/Server Application
    By Tyler_D in forum Symbian C++
    Replies: 7
    Last Post: 2006-06-15, 11:15

Posting Permissions

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