Thursday, August 29, 2013

How to move or put the android button in the middle of the screen

Ques: How to centre buttons on screen horizontally and vertically ?

Default Screen:




Ans: You need to use a Relative Layout for android GUI in the activity_fullscreen.xml  or whatever you name it. You just need to add the android:layout_centerInParent="true" on your relative layout scope.

In default android generate the layout as linear layout for your GUI activity. In that activity you can't use android:layout_centerInParent="true".


It will generate warning as ---

Invalid layout param in a LinearLayout: layout_centerInParent    activity_fullscreen.xml    /YourProject/res/layout    line 52    Android Lint Problem
How?:  

Step 1. First open the layout xml from /YourProject/res/layout .

Step 2. Change all of the <FrameLayout> ... </FrameLayout> to <RelativeLayout> ... </RelativeLayout>

Step 3.  Delete default button code portion from you xml and add the following

    <RelativeLayout
            android:id="@+id/fullscreen_content_controls"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:orientation="vertical"
            tools:ignore="UselessParent" >

            <Button
                android:id="@+id/dummy_button"
                android:layout_width="180dip"
                android:layout_height="80dip"
                android:layout_centerInParent="true"
                android:layout_marginTop="100dip"
                android:text="@string/dummy_button" />
        </RelativeLayout>
Step 4. Use the bold attribute to arrange your button on screen.


Now the output looks like ---





Tuesday, August 20, 2013

Threaded multi Chat room client source code in c++ with MFC Part - 3

PREVIOUS


ClientDlg.cpp is the class where all the action from user's are taken and initiated. The interaction with GUI to logic is so great and easy which will help any developer to understand the flow of code.

Function for login --

void CClientDlg::OnBnClickedButton2()
{
    // TODO: Add your control notification handler code here
    cTh = AfxBeginThread(
    StaticThreadFunc,
    this);
    
   m_Thread_handle = cTh->m_hThread;
}
Start the thread for a login action.

UINT __cdecl CClientDlg::StaticThreadFunc(LPVOID pParam)
{
    CClientDlg *pYourClass = reinterpret_cast<CClientDlg*>(pParam);
    UINT retCode = pYourClass->ThreadFunc();

    return retCode;
}

UINT CClientDlg::ThreadFunc()
{
    // Do your thing, this thread now has access to all the classes member variables
   

    CString txtname;
    GetDlgItemText(IDC_EDIT2, txtname);

    CString portname;
    GetDlgItemText(IDC_EDIT3, portname);
    int iPort = _wtoi( portname.GetString() );
   
    CString username;
    GetDlgItemText(IDC_EDIT6, username);

    m_pClient = new ClientCon(this);

    CT2CA CStringToAscii(txtname);

      // construct a std::string using the LPCSTR input
     std::string sResultedString (CStringToAscii);
    
    CT2CA CStringToAscii2(username);

    std::string sResultedString2 (CStringToAscii2);

    m_pClient->StartConnect(sResultedString, iPort, sResultedString2);
    return 0;
}
 Used to take input from text box and send it to ClientCon class and start the Connection with server.

void CClientDlg::OnBnClickedButton4()
{
    // TODO: Add your control notification handler code here
    CString sTextData;
    GetDlgItemText(IDC_EDIT7, sTextData);
   
    CT2CA CStringToAscii(sTextData);

      // construct a std::string using the LPCSTR input
     std::string sResultedString (CStringToAscii);
     if(m_pClient != NULL)
     m_pClient->SendData(sResultedString);
     CWnd* pWnd = GetDlgItem(IDC_EDIT7);
     pWnd->SetWindowText(_T(""));
}

This function used to send the data to server for relay the messages to other client.


Complete Source Code SERVER and CLIENT:

DOWNLOAD

Threaded multi Chat room client source code in c++ with MFC Part - 2

PREVIOUS                                                                                                                               NEXT



Client.cpp class is the MFC GUI initiation class. You can have a look here ..


BOOL CClientApp::InitInstance()
{
    // InitCommonControlsEx() is required on Windows XP if an application
    // manifest specifies use of ComCtl32.dll version 6 or later to enable
    // visual styles.  Otherwise, any window creation will fail.
    INITCOMMONCONTROLSEX InitCtrls;
    InitCtrls.dwSize = sizeof(InitCtrls);
    // Set this to include all the common control classes you want to use
    // in your application.
    InitCtrls.dwICC = ICC_WIN95_CLASSES;
    InitCommonControlsEx(&InitCtrls);

    CWinApp::InitInstance();


    AfxEnableControlContainer();

    // Create the shell manager, in case the dialog contains
    // any shell tree view or shell list view controls.
    CShellManager *pShellManager = new CShellManager;

    // Standard initialization
    // If you are not using these features and wish to reduce the size
    // of your final executable, you should remove from the following
    // the specific initialization routines you do not need
    // Change the registry key under which our settings are stored
    // TODO: You should modify this string to be something appropriate
    // such as the name of your company or organization
    SetRegistryKey(_T("Local AppWizard-Generated Applications"));

    CClientDlg dlg;
    m_pMainWnd = &dlg;
    INT_PTR nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
        // TODO: Place code here to handle when the dialog is
        //  dismissed with OK
    }
    else if (nResponse == IDCANCEL)
    {
        // TODO: Place code here to handle when the dialog is
        //  dismissed with Cancel
    }

    // Delete the shell manager created above.
    if (pShellManager != NULL)
    {
        delete pShellManager;
    }

    // Since the dialog has been closed, return FALSE so that we exit the
    //  application, rather than start the application's message pump.
    return FALSE;
}

Threaded multi Chat room client source code in c++ with MFC Part - 1

As in my previous post I have talk about server , now it's time for client. This client will use as multi chat client with our very own server. In this client you need to provide server IP ,PORT and an USERNAME.

Then just click the log in button and you are in if you get an welcome message from server.




Technology used:

i.   C++
ii.   Microsoft visual Studio 2010
iii.  MFC GUI
iv.  Winshock2 Socket
v.   TCP/UDP
vi.  Windows Thread


This project consist of  3 classes.

1. Client.cpp
2. ClientDlg.cpp
3. ClientCon.cpp


Lets start with core portion -- I mean the network level connection portion.

I have used the Winshock2 library for the purpose of network communication.

You can use this library on windows  with MVS 2010 by including library --


# include <winsock2.h>

And as it is multi user  and have GUI so we need thread. For this I have used Windows thread.
You can use this windows thread just by adding ---

# include <Windows.h>

So,  why we are late. Lets start....

ClientCon.cpp -- class works for network level connection and data send receive.

void ClientCon::StartConnect(string sAddress, int iPort, string sUsername)
{
    struct sockaddr_in server;
    char *message , server_reply[2000];
    int recv_size;
    m_pUser = sUsername;

    printf("\nInitialising Winsock...");
    if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
    {
        printf("Failed. Error Code : %d",WSAGetLastError());
        return;
    }
    
    printf("Initialised.\n");
    
    //Create a socket
    if((s = socket(AF_INET , SOCK_STREAM , 0 )) == INVALID_SOCKET)
    {
        printf("Could not create socket : %d" , WSAGetLastError());
    }

    printf("Socket created.\n");
    
    
    server.sin_addr.s_addr = inet_addr(sAddress.c_str());
    server.sin_family = AF_INET;
    server.sin_port = htons( iPort );

    //Connect to remote server
    if (connect(s , (struct sockaddr *)&server , sizeof(server)) < 0)
    {
        puts("connect error");
        return;
    }
    
    puts("Connected");
    
    //Receive a reply from the server
    while((recv_size = recv(s , server_reply , 2000 , 0)) != SOCKET_ERROR)
    {
        puts("Reply received\n");

        //Add a NULL terminating character to make it a proper string before printing
        server_reply[recv_size] = '\0';
        puts(server_reply);

        string sTempMsg ="\n"+string(server_reply)+"\n";
        m_pClient->ShowServerInfo(sTempMsg);
    }
   
}
 On StartConnect() Client initiate its socket and connect with server. Client also start listening for messages from server here. All the message from other client will traverse through server and will reach to every client.

This Class also have the function to send the message to server/other client.


void ClientCon::SendData(string sMessage)
{
    string sTemp = m_pUser +">>"+ sMessage+"\n";

    if( send(s , sTemp.c_str(), sTemp.size() , 0) < 0)
    {
        puts("Send failed");
        return;
    }
}
 This function is used to send the messages to the server by concatenating the user name to the messages.



COMPLETE CODE

NEXT

Threaded multi chat room server source code in c++ with MFC Part - 3

PREVIOUS 

Now we will talk about the other MFC GUI portion which I have created and used threaded model.

When in GUI the start button is clicked by providing port number on PORT text box this server start by creating a thread independent from GUI. You can start the server by ENTER also.


Here is some code snap for help --


void CServerDlg::OnBnClickedButton1()
{
    // TODO: Add your control notification handler code here

    cTh = AfxBeginThread(
    StaticThreadFunc,
    this);
   
    //cTh->m_bAutoDelete = FALSE;
    m_Thread_handle = cTh->m_hThread;
   
}
Here we create a windows thread for back end action.

UINT __cdecl CServerDlg::StaticThreadFunc(LPVOID pParam)
{
    CServerDlg *pYourClass = reinterpret_cast<CServerDlg*>(pParam);
    UINT retCode = pYourClass->ThreadFunc();

    return retCode;
}

UINT CServerDlg::ThreadFunc()
{
    // Do your thing, this thread now has access to all the classes member variables
    CString txtname;
    GetDlgItemText(IDC_EDIT1, txtname);
    int iPort = _wtoi( txtname.GetString() );

    if(iPort == 0)
    {
        return -1;
    }
    m_pServer = new ServerManager(this);
    m_pServer->StartListening(iPort);
    return 0;
}
On ThredFunc() we take the input from text box and pass this value on to ServerMnager class and start the server.


Threaded multi chat room server source code in c++ with MFC Part - 2

PREVIOUS


 we will now demonstrate about the class Server.cpp .

This class is the start point of the server project. It is basically used to call the MFC instance.

There will be some preview of the class here as MFC is out of scope  at the moment --


BOOL CServerApp::InitInstance()
{
    // InitCommonControlsEx() is required on Windows XP if an application
    // manifest specifies use of ComCtl32.dll version 6 or later to enable
    // visual styles.  Otherwise, any window creation will fail.
    INITCOMMONCONTROLSEX InitCtrls;
    InitCtrls.dwSize = sizeof(InitCtrls);
    // Set this to include all the common control classes you want to use
    // in your application.
    InitCtrls.dwICC = ICC_WIN95_CLASSES;
    InitCommonControlsEx(&InitCtrls);

    CWinApp::InitInstance();


    AfxEnableControlContainer();

    // Create the shell manager, in case the dialog contains
    // any shell tree view or shell list view controls.
    CShellManager *pShellManager = new CShellManager;

    // Standard initialization
    // If you are not using these features and wish to reduce the size
    // of your final executable, you should remove from the following
    // the specific initialization routines you do not need
    // Change the registry key under which our settings are stored
    // TODO: You should modify this string to be something appropriate
    // such as the name of your company or organization
    SetRegistryKey(_T("Local AppWizard-Generated Applications"));

    CServerDlg dlg;
    m_pMainWnd = &dlg;
    INT_PTR nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
        // TODO: Place code here to handle when the dialog is
        //  dismissed with OK
    }
    else if (nResponse == IDCANCEL)
    {
        // TODO: Place code here to handle when the dialog is
        //  dismissed with Cancel
    }

    // Delete the shell manager created above.
    if (pShellManager != NULL)
    {
        delete pShellManager;
    }

    // Since the dialog has been closed, return FALSE so that we exit the
    //  application, rather than start the application's message pump.
    return FALSE;
}


PREVIOUS                                                                                                                                    NEXT

Threaded multi chat room server source code in c++ with MFC Part - 1

Multi-client chat server is open source as I have created it. In this server multiple user can log in and communicate with one another as multicast user. In reality it can use as a chat room server. Can be modified as peer to peer (p2p) text chat. It can also be used as a backbone of a video conferencing project. It has a beautiful and easy to use user interface in MFC. This project is compatible with Microsoft visual studio 2010. I will describe the use of class and function with source code.




Technology used:

i.   C++
ii.   Microsoft visual Studio 2010
iii.  MFC GUI
iv.  Winshock2 Socket
v.   TCP/UDP
vi.  Windows Thread


This project consist of  3 classes.

1. Server.cpp
2. ServerDlg.cpp
3. ServerManager.cpp


Lets start with core portion -- I mean the network level connection portion.

I have used the Winshock2 library for the purpose of network communication.

You can use this library on windows  with MVS 2010 by including library --

# include <winsock2.h>

And as it is multi user  and have GUI so we need thread. For this I have used Windows thread.
You can use this windows thread just by adding ---

# include <Windows.h>

So,  why we are late. Lets start....


ServerManager.cpp  -- core network connection class. In that class I have also demonstrate how to fetch the remote client IP address from a socket connection.


void ServerManager::StartListening(int iPort)
{
    iCount=0;
printf("\nInitialising Winsock...");
    if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
    {
        printf("Failed. Error Code : %d",WSAGetLastError());
        return;
    }
    
    printf("Initialised.\n");
    
    //Create a socket
    if((s = socket(AF_INET , SOCK_STREAM , 0 )) == INVALID_SOCKET)
    {
        printf("Could not create socket : %d" , WSAGetLastError());
        m_pDialog->ShowServerInfo("Could not create socket");
    }

    printf("Socket created.\n");
    
    //Prepare the sockaddr_in structure
    server.sin_family = AF_INET;
    server.sin_addr.s_addr = INADDR_ANY;
    server.sin_port = htons( iPort );
    
    //Bind
    if( bind(s ,(struct sockaddr *)&server , sizeof(server)) == SOCKET_ERROR)
    {
        printf("Bind failed with error code : %d" , WSAGetLastError());
        m_pDialog->ShowServerInfo("Bind failed with error code");
        exit(EXIT_FAILURE);
    }
    
    puts("Bind done");

    //Listen to incoming connections
    listen(s , 100);
     char *message;
     puts("Waiting for incoming connections...");
     m_pDialog->ShowServerInfo("Waiting for incoming connections...\n");
     c = sizeof(struct sockaddr_in);
    
    while( (new_socket = accept(s , (struct sockaddr *)&client, &c)) != INVALID_SOCKET )
    {
        puts("Connection accepted");
      
        socklen_t len;
        struct sockaddr_storage addr;
        char ipstr[INET6_ADDRSTRLEN];
        int port;

        len = sizeof addr;
        getpeername(new_socket, (struct sockaddr*)&addr, &len);

        // deal with IPv4:
        if (addr.ss_family == AF_INET) {
            struct sockaddr_in *s = (struct sockaddr_in *)&addr;
            port = ntohs(s->sin_port);
            inet_ntop(AF_INET, &s->sin_addr, ipstr, sizeof ipstr);
        }

        printf("Peer IP address: %s\n", ipstr);
        m_pDialog->ShowServerInfo("Connected Peer IP address: "+string(ipstr)+"\n");
        CWinThread *cTh = AfxBeginThread(
        DataThreadFunc,
        (LPVOID)new_socket);
        ++iCount;
        sArray[iCount] = new_socket;
    }
    
    if (new_socket == INVALID_SOCKET)
    {
        printf("accept failed with error code : %d" , WSAGetLastError());
        return;
    }
}
StartListening(int iPort) Initiate a socket and Start listening on a particular port for incoming connections.

This bold letter means it can accept multiple connection( client ). In that function we used a static global variable to count the connection globally and a global static SOCKET array to stored the socket's pointer for future use from thread.

How ?

You can see on that function I have used windows thread. Here I accept the incoming connection and make a thread for every connection.

You can see that with the function --


UINT __cdecl ServerManager::DataThreadFunc(LPVOID pParam)
{
    SOCKET pYourSocket = reinterpret_cast<SOCKET>(pParam);
  
    char *message;
    message = "Welcome to Matrix chat room.\n";
    send(pYourSocket , message , strlen(message) , 0);
    char server_reply[2000];
    int recv_size;

    while((recv_size = recv(pYourSocket , server_reply , 2000 , 0)) != SOCKET_ERROR)
    {
        server_reply[recv_size] = '\0';
         for(int i = 1;i<=iCount; i++)
        {
            if( send(sArray[i] , server_reply, recv_size , 0) < 0)
            {
                puts("Send failed");
             }
        }

    }
    return 0;
}
In DataThreadFunc(LPVOID pParam) I have used the winshock send() API to sending the welcome to the client by client socket.
Here I also have a while loop with recv() API which continue to listening for client messages.
This is a static function which is called for every incoming connection for 1 time.

After receiving a message from a client this thread server now sends this message to every socket it has on its SOCKET array by fetching the socket.

NOTE :  Any smart mind can modified this function and can use for p2p message chat.


COMPLETE CODE


 NEXT



Monday, August 19, 2013

How to take input from a MFC Edit Control as string, convert it to integer and append text to it

 Take input from a MFC Control as string :

CString txtname;
GetDlgItemText(IDC_EDIT1, txtname);

Here IDC_EDIT1 is the Control Edit Text and txtname is the input at the moment we call.

Convert it to integer or int :

int iPort = _atoi( txtname.GetString() );

int iPort = _wtoi( txtname.GetString() );
// if you use wide charater formats
 
 
Append text to Edit Control :
 
void CServerDlg::AppendTextToEditCtrl(CEdit& edit, LPCTSTR pszText)
{
   // get the initial text length
   int nLength = edit.GetWindowTextLength();
   // put the selection at the end of text
   edit.SetSel(nLength, nLength);
   // replace the selection
   edit.ReplaceSel(pszText);
}

How to stop a blocking thread from another function that start in other in MFC

ISSUE: In server client scenario it is mandatory to use thread where sever is listening on a particular port.
Now in click of stop button ,how to stop this running thread.


SOLUTION:

#include <Windows.h>

HANDLE m_Thread_handle;
CWinThread *cTh;
static UINT __cdecl StaticThreadFunc(LPVOID pParam);
UINT ThreadFunc();
Step 1. Declared these on header file.

Step 2. Starting the thread from a function or button click ---


void CServerDlg::OnBnClickedStart()
{
    // TODO: Add your control notification handler code here

    cTh = AfxBeginThread(
    StaticThreadFunc,
    this);
    m_Thread_handle = cTh->m_hThread;
}
Step 3. Thread initialization function --

 UINT __cdecl CServerDlg::StaticThreadFunc(LPVOID pParam)
{
    CServerDlg *pYourClass = reinterpret_cast<CServerDlg*>(pParam);
    UINT retCode = pYourClass->ThreadFunc();

    return retCode;
}
Step 4. Work processing function for thread --

UINT CServerDlg::ThreadFunc()
{
    // Do your thing, this thread now has access to all the classes member variables
    CString txtname;
    GetDlgItemText(IDC_EDIT1, txtname);
    int iPort = _wtoi( txtname.GetString() );
    m_pServer = new ServerManager(this);
    m_pServer->StartListening(iPort);
             // while loop on start listening that are blocking call
    return 0;
}
Step 5. Now to close the thread from clicking stop button ---

void CServerDlg::OnBnClickedStop()
{
    // TODO: Add your control notification handler code here
    CloseHandle(m_Thread_handle);
    delete m_pServer;
}

Sunday, August 18, 2013

This Android SDK requires Android Developer Toolkit version 22.0.0 or above.

ISSUE: This Android SDK requires Android Developer Toolkit version 22.0.0 or above.  Current version is 21.1.0.2013-2-6-0-46.  Please update ADT to the latest version.



SOLUTION:

  1. Run Eclipse as administrator.
  2. Go to HelpInstall New Software.
  3. On Work with: type https://dl-ssl.google.com/android/eclipse/ and press ENTER.

  4. Wait for Eclipse to fetch the repository. An item named Developer tools will appear in the list.
    Mark it for install, press Next and follow the steps to install the ADT tools.
  5. When finished, it will ask to restart Eclipse. Make sure you do this.
  6. When Eclipse restarts, all your Android SDK packages should show up again.

Saturday, August 17, 2013

GUI hanged on button pressed or some action initiation in MFC project

ISSUE: In a GUI project there is lots of calculation and works are needed to be done in background when necessary . So when a button pressed or a certain action initiate the GUI may stop responding for you.


SOLUTION: In default when a MFC project is created the GUI portion has thread. So make sure the other necessary works are done on another thread (eg: calculation, process, response , internet query ).

You can have a better and great idea about thread use in mfc from this simple post

Best design for windows multi thread in a c++ class

ISSUE: How to create windows multi-threaded program in  c++ ?


SOLUTION:  Now a day maximum project or software has multiple process running at a same process.Or a gui application needs to do some work on background which is blocking. Or may be you are going to design or create a network application ,so it becomes mandatory to be an expert of Threading now a days.


Here is  the template which I follow.

In header file add the followings --

#include <Windows.h>

static UINT __cdecl CallingFunctionForThread(LPVOID pParam);
UINT WorkingFunction();
 
 
In CPP file add the followings --

UINT __cdecl MyClass::CallingFunctionForThread(LPVOID pParam)
{
    MyClass *pMyClass= reinterpret_cast<MyClass*>(pParam);
    UINT ret = pMyClass->WorkingFunction();

    return ret;
}

UINT MyClass::WorkingFunction()
{ 
    // You can do anything as a class member function and run it on your thread.
}
Start thread  from any where by adding the followings --
 
 AfxBeginThread(
    CallingFunctionForThread,
    this); 
 

How to convert between 'CString' and 'std::string' ?

ISSUE:

When you are developing MFC project in most cases it becomes necessary to convert between 'CString' and 'std::string' .

SOLUTION:

'CString' to 'std::string':


 CString sTest ("Matrix");

  // Convert a TCHAR string to a LPCSTR
 CT2CA CStringToAscii(sTest);

  // construct a std::string using the LPCSTR input
 std::string sResultedString (CStringToAscii);


'std::string' to 'CString':

std::string sTest("Matrix");
CString ResultedCString(sTest.c_str());
 

Friday, August 16, 2013

IntelliSense: #error directive: Please use the /MD switch for _AFXDLL builds in Visual Studio 2010 MFC project

ERROR:    

error C2001: newline in constant

IntelliSense: #error directive: Please use the /MD switch for _AFXDLL builds    c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxver_.h    81    3



   
Solution:
There's a bug where the settings of a generated MFC project would show "Multi-threaded Debug DLL (/MDd)"; however, it doesn't pass that argument to the intellisense engine. To workaround this problem, please try the following:

Step 1. Right-click the Project.

Step 2. Go to Config Properties->C/C++-> Code Gen ->. Double-click "Runtime Library" and set to "Multi-threaded Debug DLL (/MDd)" . If this value already appears to be set, make sure it is by selecting it again (it should then appear as bold).

Step 3. Click OK.

Done!

Lync 2010 client does not login in Lync 2013 server

ISSUE:  Lync 2010 client does not login in Lync 2013 server.


CAUSE:  The cause may be following one from 3.

i.   Client version filter in Lync SERVER
ii.  Network Security: Minimum session security in Lync SERVER



SOLUTION:

i.   Client version filter in Lync SERVER :  Here

ii.  Network Security: Minimum session security in Lync SERVER :  Here


Set NTLM authentication as first choice in lync 2010/2013 server

ISSUE: How to set authentication support NTLM in lync 2010/2013 server as first choice ?


SOLUTION:


Step 1. Run secpol.msc on Lync Front End server

Step 2. Select Local Policies  -> Security Options

Step 3. Open Network Security: Minimum session security for NTLM SSP based (including secure RPC)




Step 4. Tick on Require NTLMv2 session security (default Require 128-bit encryption)

Step 5.  Open second Network Security: Minimum session security for NTLM SSP based (including secure RPC)

Step 6. Tick on Require NTLMv2 session security (default Require 128-bit encryption)


You are done!

How to disable/enable client version filter on Microsoft lync server 2010/2013

ISSUE: How to disable/enable cleint version filter on Microsoft lync server 2010/2013


SOLUTION:

  1. Go to lync server front end. Then open lync server control panel.

  2. In the left navigation bar, click Clients, and then click Client Version Configuration.

  3. On the Client Version Configuration page, double-click the Global configuration in the list.

  4. In the Edit Client Version Configuration dialog box, verify that the Enable version control check box is selected and then, under Default action, select one of the following:
    • Allow   Allows the client to log on if the client version does not match any filter in the Client version policies list.
    • Block   Prevents the client from logging on if the client version does not match any filter in the Client version policies list.
    • Block with URL   Prevents the client from logging on if the client version does not match any filter in the Client version policies list, and include an error message containing a URL where a newer client can be downloaded.
    • Allow with URL   Allows the client to log on if the client version does not match any filter in the Client version policies list, and include an error message containing a URL where a newer client can be downloaded.

  5. If you selected Block with URL, type the client download URL to include in the error message in the URL box.

  6. Click Commit.

Friday, August 9, 2013

SIP/2.0 415 Unsupported Media Type - in lync

ISSUE:  When a lync client make a call to a custom client this issue arise.

SIP/2.0 415 Unsupported Media Type
Via: SIP/2.0/TLS 192.168.0.3:5061;branch=z9hG4bKD46A59CA.99BC04A5AF342A99;branched=FALSE;ms-internal-info="beEdEaEIWfaYJeF8c6BZ3b0XKNdvQ3PyQaRPEpAEarjbWlBLyZ_eZHbgAA"
Via: SIP/2.0/TLS 192.168.0.4:55803;branch=z9hG4bK36072482.06B5227EC88DCA9A;branched=FALSE;ms-received-port=55803;ms-received-cid=162D00
Via: SIP/2.0/TLS 192.168.0.100:50797;received=x.x.x.x;ms-received-port=50797;ms-received-cid=8C00
Record-Route: <sip:FE.domain.local:5061;transport=tls;opaque=state:T:F:Ci.R16a800;lr;ms-route-sig=adlkYhe7OeBeVys8TvobWpLmx2HSLx-xldaLJ-jRlgx4mlBLyZI12ObwAA>;tag=D5120ECF36260EB267FB812D17DAE391
From: "Test User 3" <sip:test3@fe.local>;tag=be345768e2;epid=3bcd1d97b8
To: <sip:demouser@fe.local>;epid=13757352
Call-ID: ff8f03c39c46499db228eab1eb58fed9
CSeq: 1 INVITE
Authorization: NTLM qop="auth", realm="SIP Communications Service", opaque="E74376CA", targetname="FE.domain.local", version=4, crand="13757352", cnum ="5", response="01000000ed10b4deaa20de6f64000000"
Ms-client-diagnostics: 51004; reason="Action initiated by user"
Content-Length: 0

WHY?


This issue arise due to inability of providing support for specific media type. In short--

If you ask a media player to play media it can play.
But, if you ask a media player to open a pdf it is not possible ,because it doesn't have that feature.

SIP/2.0 481 Call Leg Does Not Exist -- in lync

ISSUE 1: When make a call in lync client after certain message transaction lync caller get 481 Call Leg Does Not Exist .


SIP/2.0 481 Call Leg Does Not Exist
Authentication-Info: NTLM qop="auth", opaque="9436E22E", srand="8E281C5D", snum="12", rspauth="010000002be81caccb7d825264000000", targetname="FE.domain.local", realm="SIP Communications Service", version=4
From: <sip:demouser@edge.com>;tag=1375799463;epid=13757994
To: <sip:test3@fe.local>;tag=D5120ECF36260EB267FB812D17DAE391
Call-ID: 2jXhMAF7GVJhUA2Y8r4181MM6OlpCbvsjhzTH2Oc
CSeq: 1 CANCEL
Via: SIP/2.0/TLS x.x.x.x:59631;branch=2OyLJ5KO1GNvDbbGyOpb1pn8l2F1tFUmjiVRcvv1;received=192.168.0.101;ms-received-port=59631;ms-received-cid=1B2E00
ms-diagnostics: 2;reason="See response code and reason phrase";HRESULT="0xC3E93C09(PE_E_TRANSACTION_DOES_NOT_EXIST)";source="FE.domain.local"
Server: RTC/4.0
Content-Length: 0


WHY?

In that case it is not your problem. It means, the call that you are referring is already destroyed or cleaned from the knowledge of lync server.   

ISSUE 2: If this issue arise from remote to local or local to remote lync client call or external to internal moc call then this issue identified as another issue.

SIP/2.0 481 Call Leg/Transaction Does Not Exist

 WHY?

This means your local interface of lync server is failing certificate authentication with public interface of edge server. It means that certificate assignment is not correct for local and public interface of edge server.


SOLUTION: 

1.  Assign public cert to edge server's external interface.
    i).  Make sure that cert has the FQDN of edge server (ex: edge.domain.com)
    ii).  Make sure that cert has the FQDN of sip server (ex:sip.domain.com)
    iii).  Make sure that cert has the FQDN of avauth server (ex:av.domain.com)
    iv).  Make sure that cert has the FQDN of access server (ex:access.domain.com)
    v).  Make sure that cert has the FQDN of webconf server (ex:webconf.domain.com)

2. Assign local certificate to edge server local interface.
3. Assign local certificate to a/v server local interface.

The proper assignment of certificate what to follow has provided by microsoft as follows- 

Subject Name
Subject Alternative Name Entries/Order
CA
EKU
Assign To:
Consolidated Edge
access.contoso.com
sip.fabrikam.com
sip.contoso.com
access.fabrikam.com
access.contoso.com
Public
Server/Client
Access Edge Server
(assign from Edge Interfaces tab)

webcon.contoso.com
N/A
Public
Server
Web Conferencing Edge Server
(assign from Edge Interfaces tab)
ocsedge.contoso.net
N/A
Internal
Server
Internal interface
(assign from Edge Interfaces tab)
avauth.contoso.net
N/A
Internal
Server
A/V Authentication Port
(assign from Edge Interfaces tab)

Make file only build first file of a project in eclipse build makefile

ISSUE: When in a project make clean; make command is given although there is hundreds of files it only build one or first file of a project and stop building.


SOLUTION:  It's easy. Just give command make clean;make all . You file find that your make file is working perfectly.

Wednesday, August 7, 2013

How to enable HD video in Microsoft Lync

ISSUE:  You can change video resolution on lync client by increasing/decreasing the capture window size. The video resolution change can be either of these following type --

      1. QCIF (176×144) 15fps
      2. CIF (352×288) 15fps
      3. VGA (640×480) 15fps
      4. HD (1280×720) 13fps 

The default video resolution set on lync server normally is VGA .

1. How to know about it?

The answer is here.

2. How to change video resolution it?

Open lync server management shell in administrator mode.
Now give following command ---

Set-CsMediaConfiguration –Identity Global -MaxVideoRateAllowed Hd720p15M
The underline attribute can be either Hd720p15M, VGA600K, and CIF250K.

3. How to make sure that configuration is applied?

The answer in here.

How to know about current maximum video resolution supported by lync server

There are 2 possible way to know about video resolution configuration.

1. The hard way -- from lync server management shell.

Open lync server management shell in administrator mode.
Now give following command ---

Get-CsMediaConfiguration –Identity Global
Output:



 2. Easy way -- smart way from lync client uccapi log with out lync server.

Open uccapi log of lync client from Tracing folder .

Now search by <ucMaxVideoRateAllowed> .You will see that like ---


<ucMaxFileTransferPort>5389</ucMaxFileTransferPort>
<ucPC2PCAVEncryption>SupportEncryption</ucPC2PCAVEncryption>
<ucMaxVideoRateAllowed>Hd720p-1.5M</ucMaxVideoRateAllowed>
<qosEnabled>true</qosEnabled>
<ucDiffServVoice>40</ucDiffServVoice>
<ucVoice802_1p>0</ucVoice802_1p>

Which is your current video resolution configuration.

To change it please follow the procedure describe on here.

Monday, August 5, 2013

400 Malformed route header --"Parsing failure" in federated lync support

ISSUE:   When a lync user start call negotiation with federated user this 400 Malformed route header problem arise.

WHY?

As the federated user's are most of the case out of the local lync server and they are not the user of this local lync server edge end, they often need clear and concrete route header so that server could extract route header value in-order and route the message to remote federated client end.

Example:

Sending:
CANCEL sip:demouser@yy.com;opaque=user:epid:SsEhlbS7GFGJkfHOY836rAAA;gruu SIP/2.0
Via: SIP/2.0/TLS x.x.x.x:33360;branch=18n2L9K88eMlGn7CcctT9RwKSB1FebW397VI5uG1
From: <sip:test@xx.local>;tag=1375467581;epid=13754675
To: <sip:demouser@yy.com>;epid=fd941b3907;tag=9c85c700e3
Call-ID: BHQjMXffBDJ3cWfS4CAvb2wTByEnCZT2xxb7jecK
CSeq: 2 CANCEL
Max-Forwards: 70
User-Agent: Matrix
1. Route: <sip:ddd.yy.local:5061;transport=tls;opaque=state:T;lr>
2. Route: <sip:sip.yy.com:5061;transport=tls;epid=fd941b3907;lr;ms-key-info=AAEAAXibVCEA-ehQqI_OAWg1-HXGy3EkInAKsk_XnfP0Bi3YEKqfMhvIhCCYTmXxe7rq5jzR0t2r-3Xro344SxogHqb7E5u-qup95bHlZZn6TtF_B6acjtJBmBEGBJuMcTDmbFXy8F8yEs4K6be_BnXEbLN4reAl6fnnM3ZiHW3FJ2rlACd7ZmiGZKTQtJSj1UYod0R0xmhp9h2ZVzg0EKgJJRVFiw8Q_CxxejtrSeWz-r_swfbtunQ8Yx5gw4ZOnPA4-5iE9cA0A32UC9sbus5hmoflbHwlLBC6coRgOR77mhHlENEWVD-hu-ST310vDRoPHPHuDESLzfNx51FYaomQhJq3LoIrix0yhm3-SpWpvZukSFlOFQzmLhzKOcp9qDyxFQ5jD_5UceCN2zISwMAM5zJ2S7L8Ul9PbLSUvrPvRZmMQ9gYYXFpNT0W7Kmn5b0BTczTI0RaxyPdSWvttXZHf54aSd5ZBsQjidwe4UfhoM1hKeugfGi4ussirDH3xGl1zTkEx6g2cwkXZVvfCSRFvlE7m8_HivSPlAZ1hhEGB3Yroay9IjaQX_FTTqhivFCUbZxtTH0gtKl2pNUWLWFWPTJWojnepwPiy26qf-TX9_J8On4klv0LNfS4dYbv5QQzGgWI0ugKz0__PDuAlZAg_TkwZwwkK6zIk9fX2iTM9gBeV99Xe140jbJOUW8x;ms-route-sig=cpKH4I1JtS7c8B9C70cuDyHcDmdEwioQpamH2axMYYijK2L-D7sUkAygAA>
3. Route: <sip:edge.local:5060;transport=tls;lr>
4. Route: <sip:front.local:5061;transport=tls;opaque=state:F:Ci.R5d100;lr;ms-route-sig=fa3hMVCHMsTtGw5vppLnUTnejWyRrYeWtU5_2aZCmQ1jTdIktRI12ObwAA>
Authorization: NTLM qop="auth", realm="SIP Communications Service", opaque="514B89F0", targetname="front.local", version=4, crand="13754676", cnum ="7", response="010000007fbad6bfe83cd76e64000000"
Content-Length: 0
 Received:

SIP/2.0 400 Malformed route header
Authentication-Info: NTLM qop="auth", opaque="514B89F0", srand="068FFCAB", snum="9", rspauth="0100000047762b4d20bf8ba564000000", targetname="front.local", realm="SIP Communications Service", version=4
From: <sip:test@xx.local>;tag=1375467581;epid=13754675
To: <sip:demouser@yy.com>;epid=fd941b3907;tag=9c85c700e3
Call-ID: BHQjMXffBDJ3cWfS4CAvb2wTByEnCZT2xxb7jecK
CSeq: 2 CANCEL
Via: SIP/2.0/TLS x.x.x.x:33360;branch=18n2L9K88eMlGn7CcctT9RwKSB1FebW397VI5uG1;received=192.168.0.101;ms-received-port=33360;ms-received-cid=5D100
ms-diagnostics: 1018;reason="Parsing failure";source="front.local"
Server: RTC/4.0
Content-Length: 0


SOLUTION:  When a Lync caller get response (200 OK) against an INVITE request, this response has the Record route:  in order of callee arrangement.  So now you need to make reverse of these Route and used it in caller end. ex: if the order is 1---->3 in callee response ,in caller next request it will be 3--->1 .




488 Not Acceptable Here. - "Client side general processing error." in lync

ISSUE:  This issue arise when any user make a call to other lync user. In summary when there is a issue of INVITE message transaction. 


WHY?

488 Not Acceptable Here  issue arise due to sdp misconstruction or for invalid sdp.

 Sending:
INVITE sip:demouser@yy.com SIP/2.0
Via: SIP/2.0/TLS x.x.x.x:33360;branch=18n2L9K88eMlGn7CcctT9RwKSB1FebW397VI5uG1
From: <sip:test@xx.local>;tag=1375467581;epid=13754675
To: <sip:demouser@yy.com>
Call-ID: BHQjMXffBDJ3cWfS4CAvb2wTByEnCZT2xxb7jecK
CSeq: 1 INVITE
Contact: <sip:test@xx.local;opaque=user:epid:DbsgHp_PWlGCoMke5u6QsgAA;gruu>
Content-Type: application/sdp
Max-Forwards: 70
Supported: ms-dialog-route-set-update
Supported: timer
Supported: histinfo
Supported: ms-safe-transfer
Supported: ms-sender
Supported: ms-early-media
Supported: 100rel
Supported: replaces
Supported: ms-conf-invite
Ms-keep-alive: UAC;hop-hop=yes
Accept-Language: en-US
P-Preferred-Identity: sip:test@xx.local
Allow: INVITE, BYE, ACK, CANCEL, INFO, UPDATE, REFER, NOTIFY, BENOTIFY, OPTIONS
Ms-endpoint-location-data: NetworkScope;ms-media-location-type=Internet
Authorization: NTLM qop="auth", realm="SIP Communications Service", opaque="514B89F0", targetname="front.local", version=4, crand="13754676", cnum ="4", response="01000000856b490601dda29164000000"
Content-Length:  2867

Content-Type: application/sdp
Content-Transfer-Encoding: 7bit
Content-Disposition: session; handling=optional
v=0
o=WIND 3650253204 3948007207 IN IP4 192.168.0.101
s= Jul 23 2013
c=IN IP4 192.168.0.101
t=0 0
m=audio 41520 TCP RTP/SAVP 0 101
a=ice-pwd:CtCRycRIaDo79slChHL05Z0h
a=ice-ufrag:W2GN
a=candidate:1 1 UDP 2130706175 192.168.0.101 41520 typ host
a=candidate:1 2 UDP 2130706174 192.168.0.101 52623 typ host
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:8G/gOa60WGCt67GKSLFK0oBTHeeLjTL65WzpK+NB|2^31
a=rtcp:37661
a=maxptime:200
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=encryption:optional

Received:

SIP/2.0 488 Not Acceptable Here
Via: SIP/2.0/TLS x.x.x.x:33360;branch=18n2L9K88eMlGn7CcctT9RwKSB1FebW397VI5uG1;received=192.168.0.101;ms-received-port=33360;ms-received-cid=5D100
From: <sip:x.x.x.x:5061;transport=tls>;tag=1375467581;epid=13754675
To: <sip:test@xx.local>;epid=6c823739d0;tag=29db7c0aab
Call-ID: BHQjMXffBDJ3cWfS4CAvb2wTByEnCZT2xxb7jecK
CSeq: 1 INVITE
User-Agent: UCCAPI/4.0.7577.0 OC/4.0.7577.0 (Microsoft Lync 2010)
Ms-client-diagnostics: 52001; reason="Client side general processing error."
Content-Length: 0
CAUSE:

In that case this issue arise more invalid  sdp. From sdp we can see
 m=audio 41520 TCP RTP/SAVP 0 101 ---- Invalid
m=audio 41520 TCP/RTP/SAVP 0 101  ---- Valid

DTMF or Telephony event support on SDP and in RTP in Microsoft lync audio conference

DTMF (Dual Tone Multi Frequency) is a type of signaling used primarily in voice telephony systems. It features audible tones in the frequency range of the human voice which are typically used when dialing a call (on analog lines) or when operating an IVR menu. There are many other applications for this signaling. For more information, see the wikipedia article on DTMF (http://en.wikipedia.org/wiki/Dual-tone_multi-frequency_signaling)

DTMF RTP:

A dtmf packet is 16 bytes.

DTMF data = 12 bytes (RTP header) + 4 bytes (RTP payload)

4 bytes (RTP payload) has mapping of key press value as event. After parsing this 4 bytes the receiver end can get instruction or event what to do.

DTMF SDP:
     
       dtmf payload is 101 . It is passed on audio level of lync SDP.
m=audio 5476 RTP/AVP 101
.
.
.
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16

 a=fmtp:101 0-16  indicates the key value that is supported.

DTMF KEY MAPPING:
  1. Start the Lync Server Management Shell: Click Start, click All Programs, click Microsoft Lync Server 2013, and then click Lync Server Management Shell.
  2. Run the following at the command prompt:
    Get-CsDialinConferencingDtmfConfiguration
    
    This cmdlet returns the DTMF settings used for dial-in conferencing.

Default Mapping:

Identity                                                       :  Global
CommandCharacter                                    :  *
MuteUnmuteCharacter                                :  6
AudienceMuteCommand                             :  4
LockUnlockConferenceCommand               :  7
HelpCommand                                            :  1
PrivateRollCallCommand                             :  3
EnableDisableAnnouncementsCommand      :  9
AdmitAll                                                      :  8

DTMF USE:
If you want to mute a call in conference , then in lync key pad just type *6 .


cannot sign into communicator because your computer clock is not setup correctly

 ISSUE:
 
cannot sign into communicator because your 
computer clock is not setup correctly !!!


WHY?

This issue arise when lync server's directory control (DC) clock time is not match up with Lync Client's pc clock time.

SOLUTION:

The easy solution is that to make sure that the Lync DC system time is maximum 5 minute different then Client's PC time.

The smart solution is --

STEP 1. Goto  client pc's adjust date and time.
STEP 2.  Then on Date and Time window select Internet Time tab.

STEP 3. Now click on Change settings..  a new pop-up named Internet Time Settings will arise.


STEP 4. On Server  text field set the Lync DC / active directory IP address and click update now .

STEP 5. Now you will get DC system time and set it by clicking OK.

How to export sip and a/v certificate from lync server and edge server in lync 2010/2013.

To enable a lync user 3 certificates are necessary. These certificates are exported from lync server, edge server and directory control.

Certificate for specific services:

0. Root CA
1. SIP services/Lync Front-end.
2. AV services/Edge .


1. SIP services. :

STEP 1.  Goto run in windows button in lower left corner and type mmc.

STEP 2.  In mmc window selecte File-->Add/Remove snap-in.

STEP 3.  Select Certificates from Add/Remove snap-in.
 
STEP 4.  Select Computer Account from Certificate Snap-in.


STEP 5.   Click Next and do all of the necessary stuff on the way.

STEP 6.  Select Personal->certificates from  mmc console.

STEP 7.
  After that select the certificate you need to export and click right button of mouse and from All Tasks select export.



STEP 8.  Just follow necessary stuff and get your certificate by instruction from next click.


For Edge server certificate follow the same process used in lync server certificate.


If you find it more complex please use Digicert utility.

How to export root certificate from directory control in lync 2010/2013.

To enable a lync user 3 certificates are necessary. These certificates are exported from lync server, edge server and directory control.

Certificate for specific services:

0. Root CA
1. SIP services.
2. AV/Edge services.

0. Root CA:

You can get it from lync dc or directory control. Most of the case it is windows 2008 R2 sevrver edition.


STEP 1. Open IIS Manager from all programs and navigate to the level you want to manage.


STEP 2.  In Features View, double-click Server Certificates.


STEP 3.  Select a certificate and click View from the Actions pane.


 STEP 4. In view certificate go to details tab and click on  copy data to file .


STEP 5.  Now click Next , give certificate save  location and select all of the necessary  attribute on the way.


                                                    DONE!

How to Generate and use the ssh key on Gerrit, github.io, gitlab, and bitbucket.

 Details can be found here -