Wednesday, 28 April 2010

Tramvia vs Bus

Oggi in città mi è capitato di prendere il bus e la tramvia ad ore diciamo così 'di punta'. Non mi succede molto spesso, a Firenze, fortunatamente o sfortunatamente.

In breve, da via della Colonna mi sono recato alla Stazione di SMN col 6. Da lì ho preso la linea T1 della tramvia fino a Piazzale Resistenza a Scandicci. Prima tappa: 20-25 minuti, a passo d'uomo (letteralmente), autobus senza aria condizionata e affollatissimo. Seconda tappa: 20 minuti scarsi, aria condizionata, vetture mediamente occupate.

Ah, distanza percorsa nella prima tappa: 2 km esatti. Se fossi andato a piedi probabilmente avrei impiegato lo stesso tempo, forse meno. Seconda tappa: 6-7 km.

Il 6 è una della linee che è stata stravolta dopo la pedonalizzazione di piazza Duomo...

Sunday, 25 April 2010

Terminal Services Programming and RDP Virtual Channels...



This is a work in progress. Lately, I've spent
more than a few hours on the subject looking for information. TS developement is an interesting subject but documentation is scarce, to say the least.

The problem.

I have an application (several of them) running, in many cases, in a Terminal Server (aka Remote Desktop Services) environment. The application, running remotely on the server, needs to communicate with some hw/sw concoction "running" on the client (typically a XP/Seven PC running MSTSC.EXE, the Remote Desktop Client).

How do you let server and client speak? You could think of the following..

- Use some form of messaging on the wire, think of NT mailslots on the network for example

- Use some sql database tables as an exchange point

- Use something on a network drive (think of an Access mdb file)

- Use some form of RPC with a dedicated server (think of web services)
- Use the client file sharing feature provided by the latest RDP protocol iterations.

Well, beside being awkward, with the exception of the latter option all these 'solutions' have a problem. You cannot be sure to have the practical possibility of implementing them. Mailslots are often disabled for security reasons, tcp ports for sql and www are often disabled and with good reason. The only thing you can be reasonably sure to have is a reasonably recent RDP server/client combination and the RDP port open on the wire.

But of course it is possible to exchange something other thank keystrokes and mouse clicks and window redraws over RDP. Think of file and printer redirection: think of 3d party printing solutions like Uniprint. One should be definitely able to implement a custom 'pipeline' to let the RDP client interact with the remote application on the Terminal Server.

Well, of course you can, it's just not that terribly simple to implement.

Enter WTSAPI and Virtual Channels.

The only real API provided by Windows for TS programming is WTSAPI - It come in the form of a Win32 DLL (WTSAPI32.DLL), your typical sandwich of system functions. In a nutshell it provides two kinds of APIs. Therea are APIs to query the terminal server about information (number of sessions, client IP and such) and to control it, with some limitations. These APIs are relatively straightforward.

Virtual Channel APIs are much more interesting. A VC is a bidirectional communication link between the remote app and the remote RDP Client Application - MSTSC.EXE namely. It's the 'transport' over which Uniprint, printer and file redirection, etc. are implemented.

An RDP VC is initiated by the server application using some WTSAPI calls, directly from the app itself. The client part is a bit trickier: VC data must be handled by a custom DLL exporting a single function handling what is basically a table of pointers to other standard functions to open/read/write/close the channel. The DLL must be copied somewhere and referenced in a registry key read by MSTSC. Next time the RDP Client is run if all goes well it will call the client DLL and be able to read and write from/to the server. The communication is based on chunks of data (raw packets if you) and this must be handled by the developer. Not terribly complex of course, but not really high level. There also a couple of activex controls (mstscax.dll and MSRDP.OCX which is being phased out)

That's just what I needed! I wanna know more.

Me too. This M$ Webcast is a rather good introduction. There is the MSDN reference of course. And this old MSJ article. Oh, this official M$ blog too. It's not that much really... There's a dearth of reliable sample code (see below)

I am ashamed to ask, but I want to use VB6

If you just want to use WTSAPI function to check you ip, etc, it's possible. If you want to implement a full VC client/server application, bear in mind that you will need to:

- translate the API definitions and structure into VB (noone has still done it completely as far as I know)

- you will have to create a DLL (not an ActiveX dll) with exported functions. Possible, but not out of the box with VB6

- you will have (almost surely) to multithread. Possible, but not out of the box with VB6

- if your client is 64 bit, you're out of luck (64 bit windows MSTSC needs a 64 bit VC 3d party client DLL)

There are, though, 3d party components to ease the life of the VB6 developer. Look here, here and here. Of course 3d party libraries can be a problem, and I don't mean only the license costs.

I want to use C/C++

That's good, since WTSAPI is designed for this language. The so called samples available in MSDN are in C++. There are some samples available in the Windows SDK (aka Platform SDK) in samples\winbase\wtsapi. These samples are more than 11 years old. Even though they come with the SDK, you CANNOT compile 'em with ONLY the SDK. You need to use SDK tools and VS integration. For now, I've had luck only with VS2005, in 32 bit mode, and not with TsSysInf, the RDP VC Sample, which I suspect to be completely obsolete. This Codeproject entry uses RDP VC with C++.

I want to use Delphi.

I'd love, but now I can't look too much into it. Probably the best all around Windows developement tool, if it wasn't for Borland.. Well, I've seen there is even a WTSAPI wrapper from JEDI...

I want to use .NET

It works - one has to use WTSAPI P/Invoke, and in 64 bit too. Even though you should consider this KB note from Microsoft telling you not to use managed code for this kind of things.
But, in the limited tests I've run, it works rather good. There is a great code sample in Codeproject to demonstrate it. With a few tweaks, it really seems to work, and on 64 bit windows too.

Conclusion

Oh, these are just some reorganized notes I've posted here thinking they might benefit the occasional search engine user hitting these pages (and yours truly - blog are wonderful notes to ourselves). If I'll have the time, I'd like to further explore and elaborate on the subject.








Thursday, 22 April 2010

F@D.N likes this.

Monday, 19 April 2010

Tajani l'estemporaneo



Il neo-commissario europeo per il Turismo, Antonio Tajani del PDL, ha da poco dichiarato che il "turismo è un diritto umano", e già si parla di una cassa europea per garantire viaggi e vacanze anche ai meno abbienti. Per ora una ricerca con google news sembra dimostrare che i media italiani abbiano trattato la notizia con prudentissima incredulità... non riportandola. Inusuale: ecco qui comunque un link inglese, francese e tedesco.

Certo, ci voleva: i milioni di nuovi disoccupati europei saranno finalmente distratti dalle loro paturnie - e potranno fare un po' di compagnia ai banchieri e ai finanzieri (che grazie ai contributi salvacrisi elargiti dall'UE sono fin troppo spensierati). Certo l'idea non è nuova, ci aveva già pensato il DAF (non il gruppo new wave tedesco, un'altra organizzazione) negli anni '30 del secolo scorso con l'organizzazione KdF...

Sunday, 18 April 2010

Eyjafjallajökull

Efesto era il dio greco del fuoco, della metallurgia, degli artigiani. In una parola, il dio della tecnologia. Proprio in Italia (nella penisola del resto le contraddizioni - apparenti o meno - non sono sconosciute) fu identificato dai primi coloni Greci con Adranus, la divinità locale preposta ai vulcani. Quanto di più temibile, violento e assolutamente preda degli elementi. Successivamente Efesto-Adranus fu fatto coincidere dai romani con il loro dio del fuoco, Vulcanus.

Chissà che fine ha fatto Efesto oggi, a parte la sua apparizione - temo non riconosciuta dai più -sulle monetine da 50 lire ai tempi del miracolo economico.

Nel frattempo l'eruzione di un lontano vulcano islandese credo sconosciuto ai più, l'Eyjafjallajökull, è riuscita in questi giorni a bloccare virtualmente la quasi totalità del traffico aereo in Europa. Anche qui a Firenze l'aeroporto Amerigo Vespucci è deserto. Gli Eurostar, anche a Santa Maria Novella, sono presi d'assalto. Per non parlare di altre città più grandi. Il cancelliere tedesco Angela Merkel, rimasta bloccata a terra in Portogallo è dovuta tornare a Berlino con mezzi di fortuna, e impiegando pare più di due giorni. Altri governanti europei hanno preferito annullare tutte le partecipazioni all'estero.

I turbofan non possono funzionare con troppe polveri sottili - le stesse che invece a terra, nelle città, i nostri polmoni si sciroppano quotidianamente. Le linee aeree perdono pare centinaia di milioni di euro al giorno. L'economia europea, già convalscente per la recente (mai conclusasi?) recessione, accusa il colpo.

Tutto questo per una nube di cenere, in pochissimi giorni? Il nostro sofisticato sistema di trasporto aereo è così vulnerabile? E c'è chi dice che l'eruzione, a Thule, potrebbe durare per mesi.

Efesto, dovunque egli sia, se la sta ridendo, anche se un po' continua a zoppicare.

The worst UNIX user interface problem.


Ok, it happened to me twice, once in 1998, the other time yesterday, in 2010. I typed crontab -r instead of crontab -e, and I hit enter. I'm such a fast typist: and I promptly deleted root's crontab on one Linux server. I had a backup, yes, sort of. But it's still embarassing. Why choose two letters so close on most keyboards? Why not even ask for confirmation when you are effectively about to delete an important file in /var/spool? Why not fixing a couple of lines of code in what? twenty years...


Gear Review: LG Electronics HXD2320GB USB external hard drive


This entry should have been about something a bit different, but - ahem - I had already shot the photos above, so you get a mini review of my 2.5'' external HD, just in case somebody is even remotely interested in nondescript standard pc hardware of this kind.

I got this external 2.5'' USB external HD for a few euros at the local MediaWorld (MediaMarkt). It comes in a transparent blister box with the USB cable (there is one of those almost-standard mini USB plugs at one end found also on some Nokia cell phones) and one of those complimentary backup softwares on a mini cd-rom no one really uses. The unit is of course USB 2.0 compliant. Not every USB port/hub carries enough current to properly power the unit, hence the double USB connector - here is no external power supply provided. It works with most notebooks and the majority of desktop PCs, tough. The black plastic case, of medium quality, has a big blue power/activity LED. It's not (easily) openable, in case one would want to replace the hard disk inside. Which by the way is a standard WD3200BEVT-00ZCT0 Western Digital Scorpio 320GB 5400RPM SATA-300 8MB Cache 2.5-Inch Hard Drive. There is a preformatted GPT NTFS 320 gb partition ready to be used. No problems with Windows (XP/Vista/Seven), several Linux distros and the Mac OS. Performance is reasonable: it's decently fast, I had no particular problems carrying it back and forth from home to the office or someplace else in a business case or even in a backpack on my bycicle. An honest product for a good price.