Today I was trying to uninstall DirectX from my Windows XP box to install the latest DirectX version (DirectX 9C), for newbies DirectX is a collection of APIs used to handle multimedia applications in Windows platforms, its mainly designed for game programming to improve their performance using the DirectX video acceleration feature. The terms DirectDraw, Direct3D, DirectPlay, DirectSound, DirectMusic are often synonymous with DirectX and the DirectX runtime in general powers multimedia games in Windows.

Though there is no uninstaller available for DirectX, I tried to remove DirectX by removing the registry entry by Googling for DirectX uninstallation. For uninstalling DirectX, I removed the DirectX registry entry on Windows XP by running regedit and removing DirectX key (HKEY_LOCAL_MACHINE -> SOFTWARE -> Microsoft -> DirectX).

Now to install DirectX (DirectX 9c), I used the DirectX web setup procedure as can be found in Microsoft's DirectX End-User Runtime Web Installer page here.

But then, the installation failed throwing the below error message as shown in the screenshot below.

Fig 1: DirectX Web setup installation failure error

Fig 2: DirectX Web setup installation failure

The partial installation error log is shown below (DXError.log in C:\Windows\Logs)

Current DirectX may be a older version which does not have directx key in the registry.

--------------------
[01/19/09 16:10:21] module: dxupdate(Oct 27 2008), file: dxupdate.cpp, line: 4515, function: DirectXUpdateDownloadPlugIn

GetDXVersion() failed.

--------------------
[01/19/09 16:10:22] module: DXWSetup(Oct 27 2008), file: dxupdate.cpp, line: 386, function: DownloadPlugIn

DirectXUpdateDownloadPlugIn() failed.

--------------------
[01/19/09 16:10:22] module: DXWSetup(Oct 27 2008), file: psheets.cpp, line: 498, function: PreinstDlgProc

DownloadPlugIn() failed.

--------------------
[01/19/09 16:11:33] module: dxupdate(Oct 27 2008), file: dxupdate.cpp, line: 175, function: GetDXVersion

Failed API: RegOpenKeyEx()
Error: (2) - The system cannot find the file specified.

The registry key removal caused the installation problem, therefore NEVER remove any DirectX registry entry to uninstall DirectX, unless you have a proper uninstallation procedure, which DirectX doesn't have currently, don't try to remove DirectX by other means, or if you do so, take a backup of your registry, then the dxdiag diagonostic tool also displayed a Version not found message as shown in the figure below.

Fig 3: dxdiag showing DirectX version not found after the DirectX registry entry is removed

The Solution: Now I need to make sure that the installation procedure succeeds, somehow I need to recreate the DirectX registry entry. Therefore I looked at another Windows XP box and found that DirectX entry and recreated the DirectX registry key with its value (HKEY_LOCAL_MACHINE -> SOFTWARE -> Microsoft -> DirectX) in my box as shown in the figure below.


Fig 4: DirectX Registry Entry

Creating the DirectX entry is very simple, all you need to do is

1. Open regedit
2. Go to HKEY_LOCAL_MACHINE -> SOFTWARE -> Microsoft
3. Right click, create a new Key DirectX
4. Goto DirectX, create a new binary Value InstalledVersion and assign the value shown above
5. Create another String named Version and assign the value shown above

Unfortunately, the version I entered is the latest DirectX release version (from the other Windows XP box), so the installer assumed that my system was installed with the latest version after checking the DirectX registry entry and therefore didn't install DirectX 9.

Then I did one more tweak, which is modifying the DirectX Version string to 0.00.00.0000 in the DirectX registry entry (Open regedit, Go to HKEY_LOCAL_MACHINE -> SOFTWARE -> Microsoft -> DirectX, right click the Version String, click modify and change its value to 0.00.00.0000), as shown in the below figure.


Fig 5: Changing Version String in DirectX

Upon invoking the installer, this time it worked fine, it downloaded and installed the latest DirectX version as was shown in the figure below.

Fig 6: DirectX Installation completed Successfully

The lesson: Never remove registry entry to uninstall anything.

Socket programming tutorial

Generic Socket Programming tutorial

S.Prasanna
sprasanna199@gmail.com

This is a generic socket programming tutorial which mainly concentrates on how to communicate with two machines using TCP/IP and UDP/IP protocols irrespective of the programming language used to implement the server and client

I will list a simple Connection oriented (TCP) and Connectionless (UDP) Server and Client programs for all the four languages namely Python , Perl, C and Java. The TCP Server program is an iterative one which means it will process clients one by one. The communication between the TCP Server and the Client is a simple chat program. If the client quits, the current TCP connection between the server and the client gets disconnected and the server processes the next client and if the server decides to quit, that client gets disconnected and the server processes the next client.

The UDP Server program is very simple. The server recieves datagrams from many clients and prints them.

In all the programs , the Server process listens at port 5000 and I have used loopback address for the Server so that you can run the server and the client in different terminals in the same system. Besides you can use any of the four servers implemented in Python , Perl, C and Java with any of the four client programs implemented inthe four languages.In short you can use a Client program in Perl with a Server program in python , Server program in python with a Client progam in C , etc. Morever you can invoke the client program without any command line arguments since the client and the server are designed to communicate using the loopback address.

I will go from easy to difficult ( in terms of readability and lines of code ). i.e for example socket programming is simple and easy to understand in Python than in C or java.

1. Socket programming in Python

Connection oriented Server and Client program.

tcpserver.py and tcpclient.py

Connectionless Server and Client program.

udpserver.py and udpclient.py


2. Socket programming in Perl

Connection oriented Server and Client program.

tcpserver.pl and tcpclient.pl

Connectionless Server and Client program.

udpserver.pl and udpclient.pl


3. Socket programming in C

Connection oriented Server and Client program.

tcpserver.c and tcpclient.c

Connectionless Server and Client program.

udpserver.c and udpclient.c


4. Socket programming in Java

Connection oriented Server and Client program.

TCPServer.java and TCPClient.java

Connectionless Server and Client program.

UDPServer.java and UDPClient.java

I will list similar programs in as many languages in future. I could have explained about the details of sockets, how system calls like socket , bind, listen, etc works, but those should be explained from the perspectives different languages which is beyond the scope of this tutorial. In general these programs explain the fundamental concepts of socket programming irrespective of their implementation language.

Socket programming can be easily understood in interpreted languages like Perl and Python. Perl, especially is weapon for hackers. Dangerous scripts can be developed in minutes, in perl. For example spoofing source IP address can easliy be done in Perl but it requires some effort in C or in other languages. This small script shows how to spoof UDP source address.

Raw Sockets Programming (UDP Spoofing):

udpspoof.pl and udpserver.c

When you run the above simple script as client you can see the fake IP source address and the port the client used at the UDPServer. To execute the Perl script you need the Net::RawIP Module which can be downloaded here and also its documentation.

TCP/IP spoofing is a challenging task and involves a lot of calculation involving prediction of sequence numbers,etc but worth giving a try.

References:

1. Beej's guide to Network Programming

The highly rated Socket Programming tutorial in the Web. It explains all system calls used for socket programming in a clear way and also about Networking concepts in general.

2. UNIX Sockets for Newbies

Another Wonderful Socket programming tutorial.

3. Network Programming in Python

An excellent document on Python Socket programming.

4. UNIX Sockets FAQ

Answers to common questions asked by socket programmers.

5. Perl Socket Programming tutorial

Good introduction to Perl sockets.

6. http://pont.net/socket/index.html

A Collection of different Client-Server programs in C and Java.