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
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);
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;
}
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;
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.
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
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() );
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;
}
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
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.
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.
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.
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); }
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.
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; }
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.
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.
When finished, it will ask to restart Eclipse. Make sure you do this.
When Eclipse restarts, all your Android SDK packages should show up again.
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
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.
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 --
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);
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).
ISSUE: How to disable/enable cleint version filter on Microsoft lync server 2010/2013
SOLUTION:
Go to lync server front end. Then open lync server control panel.
In the left navigation bar, click Clients, and then click Client Version Configuration.
On the Client Version Configuration page, double-click the Global configuration in the list.
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.
If you selected Block with URL, type the client download URL to include in the error message in the URL box.
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.
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-
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.
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 --
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.
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 .
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 (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)
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.
a=fmtp:101 0-16 indicates the key value that is supported.
DTMF KEY MAPPING:
Start the Lync Server Management Shell: Click Start, click All Programs, click Microsoft Lync Server 2013, and then click Lync Server Management Shell.
Run the following at the command prompt:
Get-CsDialinConferencingDtmfConfiguration
This cmdlet returns the DTMF settings used for dial-in conferencing.
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.