Monday, March 28, 2011

Dumpbin - Checking Your Application Compiled Platform (x86 vs x64)

dumpbin is a program in Visual Studio Tools that helps you to display information in binary file. I find it useful to check whether a dll is build for x86 or x64.

Corflags is good for checking .exe, and soon, you will realize that it is not effective on checking dll files. Especially for unmanaged dll, you will see this error message

corflags : error CF008 : The specified file does not have a valid managed header
A better way is to use dumpbin with /headers options.

1. Go to start menu, find your VS2010 application folder

2. In Visual Studio Tools, click on Visual Studio Command Prompt (2010)

3. A command prompt environment will be load.

4. Navigate to your assembly location. Type, dumpbin /headers your_assembly.dll. It will display the following for x86 dll and x64 dll respectively. See the highlighted areas


VS2010 - LINK : fatal error LNK1104: cannot open file "filename.map"

I don't know why this would happen even when filename.map is created by VS2010, no permission issue and VS2010 is run as Administrator. The filename.map is 0 bytes.

The solution that work for me is to set Enable Incremental Linking to No.

1. At Solution Explorer, right click your project and click properties

2. Navigate to Linker -> General -> Enable Incremental Linking. Set to No (/INCREMENTAL:NO)

3. Click Apply and Ok

Corflags - Checking Your Application Compiled Platform (x86 vs x64)

The CorFlags Conversion tool allows you to configure the CorFlags section of the header of a portable executable image. It can also be use to check if your exe or dll is compiled under x86, x64 or Any CPU platform.

Corflags.exe come with VS2010. Use it as follow

1. Go to start menu, find your VS2010 application folder

2. In Visual Studio Tools, click on Visual Studio Command Prompt (2010)

3. A command prompt environment will be load. Type corflags will display something like follows


4. Navigate to your assembly location. Type, corflags your_assembly.exe. It will display the following


5. You will only be interested in PE and 32BIT flag. Refer to the following tables for their meanings

anycpu: PE = PE32 and 32BIT = 0
x86: PE = PE32 and 32BIT = 1
64-bit: PE = PE32+ and 32BIT = 0
6. As my assembly is compiled for x64 platform. Its PE is PE32+ and 32BIT is 0

Sunday, March 27, 2011

Visual Studio 2010 - Microsoft.Data.Entity.Design.BootstrapPackage Load Error

If you see the following warning, it means that there is some problem with your VS2010 installation. I believe I encounter this simply because I uninstall VS2010 after my first fresh install.



Regardless the reason, general fix is to uninstall, remove some registry and reinstall. This is a tedious process!!

I tried the following method and work for me to save some time

1. Open Register Editor, regedit
2. If you are 32 bit Window, remove the following

a) Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\AutoLoadPackages\{adfc4e66-0397-11d1-9f4e-00a0c911004f}, locate and remove the REG_DWORD {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB}

b) Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\AutoLoadPackages\{93694fa0-0397-11d1-9f4e-00a0c911004f} , locate and remove the REG_DWORD {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB}


c) Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\Packages\{7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} and delete this key

3. If you are 64 bit Window, remove the following


a) Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\AutoLoadPackages\{adfc4e66-0397-11d1-9f4e-00a0c911004f} , locate and remove the REG_DWORD {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB}


b) Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\AutoLoadPackages\{93694fa0-0397-11d1-9f4e-00a0c911004f} , locate and remove the REG_DWORD {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} /f

c) Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\Packages\{7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} and delete this key

4. Insert VS2010 installation disk, select reinstall/repair option to reinstall VS2010.

See: http://social.msdn.microsoft.com/Forums/pl-PL/adonetefx/thread/67cac0b5-0417-44a7-aae7-f25d1d05d41e

Wednesday, March 23, 2011

Linux - md5sum

A good way to generate and list MD5 Sum within the folder


find -type f -exec md5sum {} \;

Window Virtual PC - Slow File Transfer

When you trying to transfer a file to your Window Virtual PC, you experience extremely slow network transfer (10 - 30 kbps). On a normal NIC, this should not be the case in a un-congested LAN environment. This is mostly likely due to TCP large send offload is turned on.

TCP large send offload turned on means that TCP segmentation is being done at the NIC card. Usually, it will be done at the protocol stack. This is a problem for Window Virtual PC because it does not implement TCP segmentation at NIC card.

You can check your current offload status by using the following command at Command Prompt

netsh int ip show offload

The following will be displayed

ipv4 transmit checksum supported.
udp transmit checksum supported.
tcp transmit checksum supported.
tcp large send offload supported.
tcp giant send offload supported.

TCP large send offload supported means that your TCP large send offload is turned on at your NIC.

To turn it off, a lot of people ask you to do the following

1. Go to Control Panel\Network and Internet\Network Connections
2. Right click Local Area Connection and click properties (you NIC interface)
3. Click configure
4. Click on advance tab
5. Add properties box, look for Offload TCP segmentation property and set to Off.

It is not uncommon that this property does not exist in the advance tab. If that happen, you can try the following ways

Disable TCP task offloading in the registry of the host computer

1. Click Start, click Run, type regedit, and then click OK.
2. Locate and then click the following registry subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
3. Click Edit, point to New, and then click DWORD Value.
4. Type DisableTaskOffload as the entry name, and then press ENTER.
5. Right-click DisableTaskOffload, and then click Modify.
6. In the Value data box, type a value of 1, and then click OK.
7. Quit Registry Editor.
8. Restart your computer.

Turn off TCP large send offload at NIC card

1. Go to Control Panel\Network and Internet\Network Connections, right click properties at Local Area Connection (your NIC card)
2. Click on configure, then Details tab
3. At property look for Driver key. You need this key value to edit the register. For me, it is {4D36E972-E325-11CE-BFC1-08002BE10318}\0007
4. Now, open Regedit by clicking Start, click Run, type regedit, and then click OK.
5. Locate and then click the following registry subkey (your driver key is needed):
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007
6. Look for value LsoV1IPv4, LsoV2IPv4, LsoV2IPv6 and modify their value to 0
7. Quit regedit
8. Go to Control Panel\Network and Internet\Network Connections, disable and enable your NIC card.

See:
http://support.microsoft.com/kb/888750

Monday, March 21, 2011

Win7 - Running script on command prompt

I am not sure to love it or hate it. The security setting in Win 7 is getting on my nerve. Prompting me this and blocking me that.

This is also a problem running script such as VB script in command prompt.

I encounter the following error when running my VB script to create a user in Active Directory

Active Directory: Access is denied
My account running the command prompt is administrator, but yet, it is saying I do not have the access right.

The main reason is Win 7 (security reason) run application without administrative right. As per they recommended, you should log in as normal user and use Run as administrator (right click on the exe) whenever you want to run the application.

The same reason applies to running script on command prompt. You need to use runas command. For example, to run a script with account admin, you can do the following

runas /profile /user:domain_A\admin "cscript.exe C:\add_user.vbs"

You can use the following to runas current user

runas /profile /user:%USERDOMAIN%\%USERNAME% "cscript.exe C:\add_user.vbs"

Sunday, March 20, 2011

Win7 - AdobeUpdater No Internet connection was found

This happens when you AdobeUpdater is running and the response is
No internet connection was found. Please check your Internet setinngs or firewall

Apparently, this issue is not necessary due to Internet or firewall.

A possible solution to this is a follow

1. At Window 7, go to Control Panel
2. Locate Network and Internet and click on the link
3. Locate Network and Sharing Center and click on the link
4. At the side bar, locate Change adapter settings and click on the link
5. You will see a list of network interface. Switch to detail view for this page.
6. Look for a device name - Microsoft Virtual Wifi Miniport Adapter. Right click and disable it.
7. Run AdobeUpdater again. It should work.

See: http://forums.adobe.com/thread/422888

Friday, March 11, 2011

RTSP - RTP over TCP

Normally, RTSP provide streaming over UDP. By nature, UDP is a better choice as it provides robust streaming capability for media. However, it is unlikely to use UDP for streaming over the Internet.

Some issues with UDP are

1. RTSP/RTP over UDP requires many UDP ports to be opened (each media stream requires 2 UDP port for data and control).
2. Point 1 is a real problem as routers in the Internet may not open these ports.
3. It is normal for intermediate Internet router to filter and ignore UDP packets.
4. UDP is unreliable. Media packets may be lost when travelling along the Internet

RTSP/RTP over TCP may resolve this issue.

1. RTSP/RTP will communicate via 1 port for command and data. That is the RTSP port.
2. TCP provide reliable streaming
3. It is more likely that the intermediate Internet router allow these TCP packets to go through.

Using RTSP/RTP over TCP come with a price.

1. It complicated the packetization and depacketization process due to binary interleave.
2. TCP is reliable but have overhead. It may cause delay in real time media.

So, now I will talk about how to setup RTSP/RTP over TCP

RTSP/RTP over TCP

When you use RTSP/RTP over TCP, all command and media data will be sent through the RTSP port, normally, port 554. Also, when using RTSP/RTP over TCP, the data will be sent via binary interleave format.

Below will describe the essential for using RTSP/RTP over TCP

SETUP

To use TCP communication, you need to request TCP connection during RTSP SETUP. You have to sent SETUP command with

Transport: RTP/AVP/TCP;interleaved=0-1
This will tell the server to send media data with TCP and interleave the data in channel 0 and 1. Given in the specification, data channel is even number and control channel is odd (data_ch_num + 1). So, if you data channel is 0, your control channel will be 0 + 1 = 1.

Below is an example of TCP SETUP


RTP Data

After the setup, RTP data will be sent through the TCP socket that is used for RTSP commands. The RTP data will be encapsulate in the following format

| magic number | channel number | embedded data length | data |

magic number - 1 byte value of hex 0x24
channel number - 1 byte value to denote the channel
embedded data length - 2 bytes to denote the embedded data length
data - data packet, ie RTP packet, with the total length of the embedded data length

Below is a full example of the communication exchanged


Also, as RTSP is a application protocol, it has no way to control how TCP timeout the connection. Thus, during the RTSP SETUP, a Session is given to identify the connected stream

Session = "Session" ":" session-id [ ";" "timeout" "=" delta-seconds ]
If Session is given, each subsequence RTSP command must be sent with the session so that the server can identify the stream. Also, please note that timeout is an optional value. The default value for timeout is 60 seconds. So, it is advisable to send a RTSP command to the server every 60 second to keep the TCP connection alive.

Read RFC 2326 Section 10.12 Embedded (Interleaved) Binary Data for more details

RTSP - Real Time Streaming Protocol (RTSP)

RFC 2326 define the specification for RTSP, Real Time Streaming Protocol.

RTSP is mainly use for setting up streaming and control for audio and video media. As an overview, RTSP will be used with RTP over UDP or TCP. In this entry, I will describe the how to use RTSP as media setup command

The common commands for RTSP is OPTION, DESCRIBE, SETUP, PLAY, TEARDOWN.

The above commands set is enough to connect or disconnect from a media stream. I will briefly describe each commands

OPTION

OPTION command is used by client to ask server what type of commands does it support. The request and response example is


DESCRIBE

DESCRIBE is used by client to ask server to provide media stream information for a certain media URL Commonly, the DESCRIBE command provide the SDP, Session Description Protocol, for the given media URL. The request and response example is

SETUP

SETUP is used by client to setup necessary port, track, etc for a given media stream. It is used to tell the server what type of transport, UDP or TCP, should be used for the media streaming. The request and response example is

PLAY

PLAY command is used by the client to tell server to start providing the media stream bytes via the setup channel. The request and response example is


TEARDOWN

TEARDOWN command is used by client to tell server that the current media stream to be stop. All resource related to this stream can be removed. The request and response example is


The General flow for the commands is

To setup and play a stream

1. OPTION
2. DESCRIBE
3. SETUP
4. PLAY

To Terminate

1. TEARDOWN

As a complete example, the flow of command for client and server to setup and play a unicast media stream is


Below is a screenshot of RTSP commands in action


JAVA - Create RTSP Connection

Using Java to create RTSP connection is simple. Below is an example for sending a OPTION command

Socket s = new Socket();
s.connect("rtsp://your.url:554/track.sdp", 60000);
s.connect(address, timeout);
PrintStream out = new PrintStream(s.getOutputStream());
StringBuffer b = new StringBuffer();
b.append("OPTIONS * RTSP/1.0 \r\n");
b.append("CSeq: 1\r\n");
b.append("User-Agent: MyClient \r\n");
b.append("Connection: Keep-Alive \r\n");
b.append("\r\n");
out.print(b.toString());
out.flush()

Above provide a skeleton code for using JAVA to create a RTSP OPTION command. As you can see, all you need to do is to the follow

1. Create a JAVA socket
2. Use the socket output stream to send the commands. Simple follow the respective command as state in the above section.
3. After sending, read in the response from socket input stream socket (s.getInputStream())and parse it respectiviely.

NOTE: If you have notice, at the end of the command, I provided an extra

b.append("\r\n");

This is needed to tell RTSP server that the command is ended. It is a common mistake when trying to communicate with a RTSP server.

For more details you can find in http://www.ietf.org/rfc/rfc2326.txt

Hadoop - How to setup a Hadoop Cluster

Below is a step-by-step guide which I had used to setup a Hadoop Cluster Scenario 3 VMs involved: 1) NameNode, ResourceManager - Host...