Showing posts with label howto. Show all posts
Showing posts with label howto. Show all posts

Thursday, February 21, 2019

How to install a .Net based Windows Service using InstallUtil.exe, see its status, start/stop it



How to Install a Windows Service Using InstallUtil and command prompt from Naeem Akram on Vimeo.




A demo day be really frustrating or it can be the happiest day of an IT professional's life.
Now I'm going to demonstrate the stuff which we've created so far in this course

You may join my course with special discount using the link given below.

https://www.udemy.com/tcpip-socket-programming-for-coders-using-csharp-net/?couponCode=HALF


The windows service solution is already open
I'll go and click build and build solution
Now I'm going to expand solution explorer
And click the button , "Show all Files"
Next I'm going to expand the "bin" folder
 then I'll right click the "debug" folder and select "open folder
 location"
 Take a brief look at the contents of this folder
The file Udemy Windows Service dot exe is going to run as our service.
For this purpose, we're going to use installutil.exe
It is shipped along with Microsoft .Net framework.
For this purpose I'm going to launch the developer command prompt
I'll click the Windows Button and type "Developer command prompt"
The developer command prompt for vs is showing on top
I'll right click this shortcut and select menu option "Run as
administrator"
Now I'm going to type the command installutil.exe space -i space
And then the path of the file which we want to install as a service.
I'll go back to the debug folder and shift right click the Udemy
Windows Service .exe file
I'll select the context menu option "Copy as path"
Now I'll go back to the command prompt windows
I'll right click it and select context menu option edit
And then select Paste

The full command is installtuil.exe pace minus i space path of
our windows service exe file
I will hit enter key on command prmopt

The system shows that the commit phase completed successfuly

Let us see if the service is showing up service control managter
or not
I'll open the SCM by pressing Windows R and typing services.msc
Inside the name column, I'll look for Udemy Demo Service
We can click inside the name column and press Udemy
You can see our very own Windows Service named "Udemy Windows Service"
 along with the descritpion
"My hello world servoce" right here
And it has got logon as "Local System"
You'll see that status of the service will change to "Running"
The actions button on top right will also change from start to stop
 and restart
I'm now going to click the stop link and that should stop the service
without any fuss
You see a progress bar popup
And the service status is changed to stopped.
That is it for this video
In the next one we'll take a look at the event log



Monday, February 4, 2019

What is socket programming?


Socket programming is, first of all, a means of boosting ego among the geeks and nerds who know it.
There are two types of programmers, one who has done socket programming and one who has not.

You may learn socket through the discounted links below; I teach two courses about socket programming on Udemy.

https://www.udemy.com/tcpip-socket-programming-for-coders-using-csharp-net/?couponCode=HALF

https://www.udemy.com/course/udpsocketprogramming/?referralCode=9A39D0BAEBF79DBDE6A3


Aside from this difference, the term "socket" is referred to a software-level construct that can be used to access a computer network. The term "access" encompasses two things:

  1. A computer reading data from the network sent by another computer
  2. A computer writes data to the network to send it to another computer

It appears simple when we send a message over a computer network using an app like Whatsapp. But there's a lot of complexity going on underneath it. Even the programmers must be shielded from the radiation of things like the OSI model and BGP. That's where sockets come in. Let me give you the simple definition of a socket.

Socket: 
A socket is a variable you can create in a high-level programming level, such as C#, Java, or C++. Once you have the socket, you can send and receive data using the computer network.
A socket is like an abstraction. It hides a lot of complexity under it and lets the coders write code that results in transmitting their data through WiFi, Ethernet, or any other means.
Sockets are often exposed through various APIs.

A few examples of socket APIs are given below, along with their mother languages.

  1. Java - java.net.*
  2. C# - System.Net.*
  3. C++ - socket.h

Windows provides an implementation of sockets through WinSock2 API. This is, in turn, used by runtimes like JVM(Java Virtual Machine) and .Net CLR(Common Language Runtime).
You don't need to learn C to work on this course.



Wednesday, February 25, 2015

Cocos2D-X Game Development in Android Studio

When we create a new Cocos2D-X project using Cocos2D-Console, an Eclipse project is generated by default. The problem is that Google needs to drop support for Eclipse ADT; they're fully pushing IntelliJ Idea-based Android Studio.
This post will show you how to convert your Cocos2D-X Android Eclipse ADT game project into an Android Studio project and how to configure NDK and JNI in Android Studio to run your game from Android Studio directly.

Note: A reader recently commented that he was using Cocos2D-JS on Linux; this article helped resolve his problem. Things get buried in the comments section; that's why I am putting an important fact inside the post. Please read the comments section; it has some valuable information.

Please check my Udemy course:

Important

  Look at the previous article in this series; the link is below. This article explains essential concepts like setting important environment variables like NDK_ROOT. The article also shows you how to compile a project in obsolete Eclipse ADT. A quick look will be helpful.

Compile Cocos2D-x Project For Android Game Development


Create a new Cocos2D-X Project

First, let's create a new Cocos2D-X game development project; you may skip this part if you already have a project. Run the Cosos-Console command.
cocos new -p com.honesitconsultancy.indiegame -d "D:\Cocos\Projects" -l cpp "IndieGame"

Fig 1: Cocos-Console New Project


Once the command line operation is done, you will have a new " IndieGame " project folder on the path "D:\Cocos\Projects\." The folder will look like the screenshot below:

Fig 2: Cocos2D-X New Project Structure

1. Import Android project into Android Studio

Run Android Studio; if you already have a project opened, close it. Otherwise, it will show the project selection dialog exhibited below:
Fig 3: Android Studio New Project Dialog


I've blurred the project names on the left to hide the names of a few client projects I'm consulting through oDesk.


  1. Click on the item "Import project(Eclipse ADT, Gradle, etc.)
  2. The project selection dialog will open. Browse to your game path; in my case, it was "D:\Cocos\Projects\IndieGame\." The user interface did not show the subfolder " IndieGame "; I had to click the refresh button.
  3. Select the Android project generated by the Cocos-Console command line. The name currently will be "proj.android". The refresh button is highlighted by a circle, and the Android project is shown by an arrow.

Fig 4: Select Project Dialog Android Studio

The following dialog will ask for a path to save the new Android Studio project. You must keep the new project alongside the other projects.
Fig 5: Android Studio Select Destination Path

  • Change the name of the project folder to proj.androidstudio and click Next

You'll see a few options on the next screen. Android Studio is trying to help you; we don't need it. Check all 3 check-boxes reading "Replace jars with dependencies, when possible,"; "Replace library sources with dependencies, when possible,"; and "Create Gradle-style(camelCase) module names" on the next screen, as shown below. Click the Finish button.

Fig 6: Android Studio Import project from ADT Options


The Android Studio will ask that the directory does not exist and do you want to create it? Click "OK" and a new directory/folder will be created for you.

2. Add NDK to your project properties

Android Native Development Kit(NDK) path will be added to your "local.properties" Android Studio project file, an auto-generated file.
Click on the proj.androidstudio name on the top left of your screen, and select local.properties as shown in the screen grab below.
Android Studio Open local.properties


By default, this file will contain the path to Android SDK, don't mess with it. We need to add a line of text below the existing SDK line.
The format of the NDK entry will be ndk.dir=%Path of your NDK directory%
In my case, the precise statement is shown below:

ndk.dir=D\:\\cocos\\android-ndk-r10d-windows\\android-ndk-r10d

Important: Windows users must modify the path string and add a backslash in the following places:
  • Right after the drive letter
  • Right every backslash in the path
Save the local.properties file and close it.

3. Modify Build.Gradle to handle JNI

  • On the top left, click proj.androidstudio
  • Click IndieGame(or whatever project name you've chosen)
  • Click build.gradle




Add a new line right after closing bracket } pertaining to defaultConfig section.
Add the following magic lines down there:

sourceSets.main
            {
                jni.srcDirs = []
            }
The sourceSets.main line will enable using Java Native Interface or JNI in your project. JNI does the same thing as Interop on Microsoft .Net.









Running your Cocos2D-x Indie Game on Android Devices

We need to perform just one more step before hitting the build icon.

  • Open a command prompt.
  • Change the directory to the location of your project.
  • Once there, type the following cocos-console command.

cocos compile -s ".\proj.androidstudio" -p android --ndk-mode debug

Be Patient: I got a system with Core-i7 CPU and 8 GB RAM; my system takes about a minute to compile the code. If someone's got a slower/older system, getting a cup of coffee while the code compiles is a good idea.

4. API Level 9 Error

By default, the Cocos-Console generates a project with Android SDK level 9. It's an old platform; if you still need Android Studio installed, it will show an error. To fix the problem, you must modify the Android SDK level values in your game Manifest.xml and Gradle configuration file.

4a. Changes in Gradle Build File


  • Luckily you would already have the Gradle file opened to make half of the changes(otherwise, follow Modify Build. Gradle to enable the JNI section above). Find the defaultConfig section shown below and change values accordingly. I got platform 14 installed, so I changed it to 14.


defaultConfig {
        applicationId "com.honesitconsultancy.indiegame"
        minSdkVersion 14
        targetSdkVersion 14

        ndk {
            moduleName "cocos2dcpp_shared"
        }
    }


  • Change the compileSDKVersion value as well. By default, it was 10; I'll change it to 14.
  •     compileSdkVersion 14
Save the file.

4b. Changes in Android Studio Manifest File

Now open the Manifest file; you can do so by clicking the project name hierarchy as shown by the thunderbolt in the screen grab below(proj.androidstudio -> IndieGame -> src -> main). I replaced the arrow; it looked boring :)


We need to change the minSDKVersion property here. We'll change it to 14(or any suitable SDK platform level you got installed).

<uses-sdk android:minSdkVersion="14"/>

After changing the value, save the manifest file. And hit the Synchronize button as well.

How to Make The Cocos-2DX Project

Here comes the climax!

Click the "Build" menu and select the "Make Project" menu item. You may use the shortcut key Ctrl + F9
Again, stay calm and wait for a while as the project is done.
Click the "Run" button, or use the shortcut key Shift + F10.

Note: I assume you've already configured a phone or emulator to work with your Android Studio; how to do so is beyond the scope of this article.

Once your blank Cocos2D-X game project starts running, the following screen will be displayed by default:
Please feel free to post comments on this blog and check other articles in this series. You may contact me via e-mail using the form at the top left of this post.
I will post more stuff; you better subscribe to the mailing list.

Monday, February 23, 2015

Compile Cocos2D-x Project For Android Game Development

honest-it-consultancy-game-development-android
My first Cocos2D-X game development project Running on Android Mobile

The code we write in C++ is used as it is to generate a build for Android platform using the tools supplied by Cocos2D-x engine. The platform dependent layer is very thin and lightweight, and you don't have to mess with it to develop Android game.

Compile Cocos2D-x Project using NDK & Cocos2d-Console

First of all we need to compile our Android project using Android NDK(Native Development Kit). You will need to download Android NDK first as mentioned here. Once you have the Android NDK.

Sunday, February 22, 2015

Cocos2d-x: How to create a new project(Android, iOS, Windows)


cocos new -p com.honesitconsultancy.indiegame -d "D:\Cocos\Projects" -l cpp

cocos-2dx-project-structure
Fig - 1: An empty Cocos2d-x Project
Once you have all the pre-requisites needed for working with Cocos 2Dx game development installed on your Windows PC, you are ready to use one of the best cross platform indie game development engines.

A new Cocos 2DX C++ project is created through a Python programming language script, remember Python was listed in the list of software we need to install beforehand. To read about list of prerequisites needed to create cross platform games with Cocos2d-x is visit following link:


Fig - 1 shows a new empty Cocos2d-x project. You can see it already contains projects for iOS, Android, and Windows(win32).

How to create new project using Cocos2d-console

Well that's just a fancy name for a Python script. Even the file name is different, "cocos.py".
When you install Cocos framework, the path is automatically configured and you can type "cocos" anywhere on command prompt.
This script file is present in Cocos framework installation folder(FYI). In my case I installed it on path "C:\Cocos". Full path of Cocos2d-x is given below:

C:\Cocos\tools\Python27\Tools\Scripts

The how-to guide present on Cocos website tells a different path, I couldn't find it on my PC and discovered this by just searching for .py files in the installation folders.
Launch command prompt, and type the command given below








cocos new -p com.honesitconsultancy.indiegame -d "D:\Cocos\Projects" -l cpp

Important: Please create the project path folders before running the command, i.e. the path specified through -d switch.
cocos-2d-new-project-screenshot
Fig-2: cocos2d-x console screenshot

To learn more about the Cocos2d-X console, type following command to get the list of Cocos2d-x console options

cocos new --help

A screenshot of the help description is shown below
cocos2d-studio-help
Fig-3: Cocos console help 

How to write Cocos2d-x code using Visual Studio 2012

Go to the path which you specified in command line for creating a new project. Please refer back to Fig-1.
Open the folder "proj.win32", this folder will contain a solution file which will be named "indiegame.sln" or "MyCppGame.sln" in my case.
cocos-2dx-win32-project-contents
Fig-4: Cocos2d-x new Windows(win32) Project contents
A screenshot of how the project looks inside Visual Studio is given below:
cocos2dx-visual-studio-inside
Fig-5: Inside Visual Studio 2012 Cocos2d-x C++ Project

Where will you write the code?

To start with we will put the code inside HelloWorldScene.cpp file. If you're going through the programmer guide doc, try your practice code in the C++ function mentioned below

bool HelloWorld::init()

Here's a short video demo to show off and make you jealous :D


For places with Youtube blocked, Vimeo video

Cocos2dx Visual Studio Helloworld Demo from Naeem Akram on Vimeo.

What about Android, iOS and other platforms?

First of all, refer to Fig-1 you will see there's a folder "Classes". This folder is utilized by Cocos2d-x framework to generate object files/dlls which are then used by all projects. Any change you make in Classes folder will be systematically used in Android, iOS,Windows, and Windows Phone Project(what?).

Just yesterday I figured how to build and run a Cocos2d-x game project on my Android phone. In a few days I will write another blog post about how to run your Cocos2d-x indie game project on Android using NDK(Native Development Kit) and Eclipse IDE.

Stay with me on this journey to learn game programming, and feel free to communicate/ask questions. You may post a comment or send me an e-mail through the form on right side of page.

Stay tuned for more!

Tuesday, February 17, 2015

Getting Started With Cocos 2D using C++ on Windows, What To Install?

cocos-2dx

Cocos 2d-x is a very popular cross platform game development engine. C++ is the programming language most university/college students now right out of college, that means maybe they can create a game while studying in college! Unity 3D, another game development platform is taking the market by storm but still many professional developers prefer Cocos 2D. My friend Mudaser recommended using Cocos-2D instead of Unity, he's got several years of game development experience so I followed his advice.


Getting started with Cocos was not very easy to be honest, it took me several hours to figure out which way to go. They got documentation on their website but it was not very helpful.

Tools to install for developing Cocos 2D C++ games on Windows





  1. Cocos Studio - Download
  2. Cocos Framework - Download
  3. Python - Download
  4. Visual Studio 2012 - Download
  5. Windows Phone 8 SDK - Download
  6. Java Development Kit (JDK), for Android version of your game - Download
  7. Android SDK, or Android version of your game- Download
  8. Android Native Development Kit (NDK), for Android version of your game - Download
I compiled this list after spending some time and I believe it is going to be helpful for people.

Tip

Most of the stuff can be downloaded after installing Cocos Studio on your system through the Cocos Store tab shown below. I recommend downloading Cocos Studio first.


cocos-store

Are you struggling with Cocos 2D-x game engine, let's learn together!!!

Feel free to get in touch with me through the "Contact Me" form on left side, you may comment the blog post as well.

What is Cocos Studio then?

It is not the place you will write your code in. Instead, it is a place where you create scene files which are then used by a programmer.
Your project will have various folders containing projects for Win32, Android, and Windows Phone as well. You will open appropriate project folder and modify files in there.

Why Python?

Not everybody loves PowerShell, open source community has got a much older and well tested alternative i.e. Python programming language. It is used to perform various tasks like creating projects etc. You will need to install it as well, no way around it ma techie.

Where do you write the Cocos2D-X game code?

On a Windows PC, the C++ game code is written in Visual Studio 2012. On a Machintosh, XCode is used to write and edit code. Same code can be reused as it is to generate an Android and iOS version of your game. You will need to provide graphics for major size changes, but don't worry about that for now.

Is it possible to create a Cocos2D-X game without C++?

Yes, it is possible to write HTML5/JavaScript based games, the tools are not covered in this blog post.
Lua scripting language is also supported and it can be used to create Cocos2D-X games.

android-os-logoNo direct debugging on Android

Don't just freak out, that's a matter of fact. You can't debug directly from Android devices. That's why its recommended to use Windows Phone emulator on Windows.
There is a good news for Apple iOS developers, they can directly debug their game code from their device. The reason is objective C is a child of C and it supports code written in C++.
On the contrary Android uses a virtual machine to run code, and C++ code gets converted into suitable byte code and back to assembly before hitting the processor.

Friday, February 13, 2015

SQLite Date Time Functions Examples


SELECT strftime('%Y', trxDateTime) as sYear 
FROM trx_log
This is the SQL for selecting year part of a date time column from an SQLite data table. For more explanation & examples, please keep reading below. 
Computer time

We have an SQLite database table named 'trx_log'. This table contains a string date time field trxDateTime. It also contains other columns like trxTargetNumber, trxAmount, trxStatus. A snapshot of table schema is given below, some sample data is also included.

sqlite-android-search-by-year-group-by-month
Example SQLite Table for query



All fields other than trxAmount are string, only trxAmount which represents a superficial transaction amount is a number type.

SQLite Year calculation function

Sqlite provides strftime function to extract specific part from a date time string. We will use it to find out year in SQLite. Sample SQL query code is given below:

SELECT strftime('%Y', trxDateTime) as sYear 
FROM trx_log
This query will return four rows of data (based on snapshot shown earlier) each containing 2014 and labeled sYear.
The first parameter here is a format string, in this format string %Y represents a year.
Please notice that the Y here is a capital letter.









How to make where clause based on year in SQLite SQL?

You will get the year part of a date using strftime function and then make a decision based on that. For example, if we want data from year 2014 we can use following query.

SELECT strftime('%Y', trxDateTime) as sYear 
FROM trx_log WHERE  strftime('%Y', trxDateTime)='2014'  

Same technique can be used to group data based on year as well. Use of this technique to group by data is well demonstrated in following post:
http://aprogrammersday.blogspot.com/2014/02/group-by-month-or-year-and-sum-in-sqlite.html
Database SQLite

SQLite month calculation function

The strftime function can also be used to find out the month section from a date time string column. The exact SQLite SQL query for finding the month is given below

SELECT strftime('%m', trxDateTime) as sMonth 
FROM trx_log
The query mentioned above will return four rows of data (based on snapshot shown earlier) containing 02 as month. It is worth mentioning again that the m in this case will be a small letter. Capital M will cause the SQLite engine to return minutes instead of month.

How to make where clause based on month in SQLite SQL?

It is very easy to use a month field as basis of a where query or group by operation in SQLite. We will use the same strftime function again. An example SQ< query is shown below.
SELECT strftime('%m', trxDateTime) as sYear 
FROM trx_log WHERE  strftime('%m', trxDateTime)='02'  
Please note that SQLite will return months between January to September as two digits where the leading digit will be 0 always. For months December to 

SQLite day calculation function

How to find a day from SQLite table using SQL? Use the strftime function and supply appropriate formatting string in first parameter. The SQLite SQL query for finding the month is given below:

SELECT strftime('%d', trxDateTime) as sDay 
FROM trx_log

How to make where clause based on month in SQLite SQL?

You can also use strftime SQL(Structured Query Language) function to filter data and group data it by certain values of a specific day. I showed you earlier how to find out the day from a SQLite date field. How to use it in a select statement in conjunction with a where clause is shown below:

SELECT strftime('%d', trxDateTime) as sYear 
FROM trx_log WHERE  strftime('%d, trxDateTime)='02'  

Wednesday, July 23, 2014

iPhone UDID using iTunes

How to find iPhone UDID (Unique Device Identifier using iTunes)

Plug your phone in to your PC/laptop and start iTunes software.

Click on phone icon highlighted in image below, don’t click the eject button
iphone-udid-itunes-graphic1

Another UI screen will be shown as a result of this click, the UI screen looks like following:


Only after a single click, the text label will start displaying the UDID of the phone which is needed for enabling testing on tester devices. 

iphone-udid-itunes-copy-udid


Right click the cryptic looking alpha-numeric string and select copy. Please note that I have distorted the UDID intentionally.
Now you can paste it anywhere and email me, or even get it tattooed on the biceps.

What is a UDID?

The iOS device UDID is added to a provisioning profile, it allows ad-hoc deployment of your apps during testing to the iOS devices of your testers. You would've already guessed that its a unique identifier and no other Apple mobile device will have this identifier on it.

Please note that only 100 iOS devices be it iPhone/iPod/iPad can be added to a single Apple Developer Account.

In case of Android, you can create a development build and send the apk file to any number of people who may deploy it on any number of devices.