Sunday, February 29, 2004

Re: communicating to a modem

There was this thing I'd tried back in junior college days. Basically, you connect to a friend's computer using hyper terminal. On the server side, you punch in the command ats0=1 or something like that; don't remember exactly. Then a friend would dial into my computer using the modem and we could transfer files. It was a good way to transfer files too big to mail. And it was pretty quick too (about 4 KB/s... yeah that's quick... quicker than dialup downloads :-))

I've a question... is there a program which I can use to make / answer telephone calls? Something which runs in the background and tells me when the phone rings (assuming I don't have a regular phone connected) so I can answer it using the computer itself... listen on the sound blaster and speak into the mike connected to the sound card. I tried the phone dialer one time but I think it just dialed... so wasn't a complete telephone call. Are there any settings which have to be tweaked or something like that?

communicating to a modem

when i first did tried this it definitely was a "eureka" moment for me. i doubt how many of you broadband guys (yup .. i am still on dial-up) still have a modem though.

basically i'll show you how to issue commands to your modem. the modem can be programmed to perform various tasks.

goto start>>programs>>accessories>>communications>>hyper terminal. you will be asked to create a new connection. just give any name you want. in the connect to option give COM1 or the similar COMx port where your modem is connected. in the next window, you can set Bits per Second to 9600. after ok you are connected to your modem.

now you have a blank text window staring at you and thats all. type in at and voila, you get a reply OK. that was your modem talking. in modems, standard commands have been defined. this protocol is called AT-command set. the command you issued earlier was attention (at). you asked the modem for it's attention. just a sort of are_you_present check. another command is ATDT=xxx which will dial through your modem to the number xxx. there are many other codes which you can google for.

also the modem can reply in numeric or verbose format to your commands. numeric commands are well, numeric like 0 1 2 3 .. each have meaning as described per command. verbose commands are like OK CONNECT RING BUSY etc.

so you can create an app, which communicates with the COM port, and listens for the above strings, after passing the commands. and can talk on the phone through your the pc. there are two modes of communication with a modem actually, a data mode and a command mode. in the command mode the modem respods to stuff like AT etc. when you convert to data mode, everything you send to the modem is just passed through. ATA, ATH, +++ are some more useful commands. i haven't explored or tried this much so not very sure of some things.

and it gets better. for mobile communication there exists a AT+ command set. instead of a normal modem you can connect a Nokia 30 GSM terminal to the pc. now just insert a sim card and communicate wirelessly. the AT+ command set is a super set of the AT commands. advanced commands exist for operations supported by mobile devices, like sending SMS'es. also can use advanced, faster mobile protocols like GPRS etc.

i have just given a brief overview of the stuff within limitations of my knowledge. please google further for more info. also i suggest that you read more on the Nokia 30 terminal. also it seems that Nokia 31 terminal has been released. dinesh could also add on to this blog.

in linux there is an app minicom which is the equivalent of hyper terminal.

thinking in flash

How well do you guys know Flash? Everything on there is done in Flash. I'm just wondering how much "programability" Flash offers. Cause it looks quite compilicated to me.

i used to do quite some stuff in flash long back. quite some programming also. one very good site for flash resources is flashkit.com. did a few projects which gave me a lot of satisfaction. there was a time when i was much better at flash than at java actually!!.

i guess i was comfortable with flash because i thought of it in a more OOP way. flash == OOPS with images. i'll explain further.

there are a few object types. movie and button are the most important. when you create a movie or button symbol you are in effect extending the basic classes to create your own. the symbols you put on stage are also just called instances. you also have to give instance names to whatever instances you put on stage. the one in the library is the extended class.

there are some super methods/variables you have when you extend the movie or button classes. these are the api calls you can make to manipulate your instances. stuff like x._alpha etc. the entire api is very well documented in flash help.

another very important part in flash is handling events. buttons and movie instances also have associated events, which you can trap and use. stuff like
on (press){
getUrl("products/index_warli.html","_self");
}
for buttons. basically event handlers/delegates whatever.

in programs you start from a main and flow through a program and create instances, call methods etc. in flash you flow through the frames. simply stop(); at a particular frame, and jump with gotoAndPlay(5); on some event etc to move through the animation.

i would say think partly OOP!!

Saturday, February 28, 2004

Good Assertions example

I was just looking over some code I had written sometime back and came across something that I thought would be a good area to use Assertions.

This has to do with using enums. Enums in c/c++/c# (and coming soon to Java in 1.5) are types which consist of some named constants. They are much preferable to just constants or "magic" numbers cause they are much clearer and are categorized.

Anyway, here's a simple ex of using it...

enum Color
{
    Red,
    Blue,
    Green
}

If your method takes a Color argument it can work with the values set in this enum.

private void ChangeBackground( Color color )
{
    switch ( color )
    {
        case Color.Red:
            // Change background to red
            break;

        case Color.Blue:
            // Change background to blue
            break;

        case Color.Green:
            // Change background to green
            break;

        default:
        // Don't do anything
        break;
    }
}

This is fine, but what if sometime in the future someone adds a new value to Color? That switch statement will drop down to the default case. And you won't even notice it.

So it would be good practice to add an assertion in the default case.

default:
    Debug.Assert( false, "ChangeBackground(): Color " + color + " was not recognized" );

This is basically protecting yourself from your own code. In this example, it's not such a huge deal if it falls through to the default case... just that your newly added color won't be handled. But in other cases it might be more critical.

Re: levitated.net

Pretty cool stuff.

How well do you guys know Flash? Everything on there is done in Flash. I'm just wondering how much "programability" Flash offers. Cause it looks quite compilicated to me.

Friday, February 27, 2004

levitated.net

you guys have to check this out

http://levitated.net/
http://www.levitated.net/daily/index.html

the stuff here really blew my mind!! simply awesome

dinesh.

Wednesday, February 25, 2004

We Are Morons: a quick look at the Win2k source

http://ww.kuro5hin.org/story/2004/2/15/71552/7795

No doubt you've heard about the Win 2K/NT source code leak. This article just takes a superficial look at it.

I'm guaranteeing you'll shit your pants laughing at some of the source code comments.

Re: Return of the Assertions

assert can be enabled/disabled during running code however, with the -ea , -da options.

how is it in .net ?


The .NET languages don't have an assert keyword. The framework has a class called Debug in the System.Diagnostics namespace which has an Assert() method.

The CLR depends on the presence of a "DEBUG" symbol to JIT compile Assert calls. You use the #define statement to define the symbol -> "#define DEBUG". The methods in class Debug have an attribute called Conditional associated with them. Ex...

public class Debug
{
[Conditional("DEBUG")]
public static void Assert( bool condition );
}

At compile time (i.e. JIT compiling to native code from IL code), when it comes across the Assert() methods, it sees that it has the Conditional attribute associated with it. It checks to see if the DEBUG symbol is defined. If yeah, it goes ahead and compiles, else skips it. So, no increase in code size and doesn't hurt performance.

Actually .NET has another class called Trace. That class also has Assert() methods, which essentially do the same thing as Debug Asserts. The difference is that Trace uses a different symbol. It uses "#define TRACE". Also, the Conditional attribute on those methods are passed "TRACE".

They have two cause you want some assertions only during debug time, (Debug.Assert()) and others ALL the time, even on release builds (Trace.Assert()).

another question (probably the dumbest however) i had is whether FooBar is supposed ot mean anything. as i i have seen so many FooBar examples, i wonder if it was some historic programming whatever. u guys know what its supposed to signify or do i just need a break !!

I don't really think it means anything specific. It's just something that's been passed from gen to gen in program examples and it's stuck. Here's a def from the "The Jargon Dictionary" http://info.astrian.net/jargon/terms/f/foobar.html

There is another acronym that sounds the same - FUBAR (Fucked Up Beyond All Recognition)

Friday, February 20, 2004

Binary finger counting

http://www.johnselvia.com/binary/bin1-7.html

The next time you're pissed off at some one, send em a 4... unless your in England. In that case go for a 6.

Re: iptables

there is actually so much stuff i can ask you on linux actually. did u try kernel 2.6? i tried compiling but on restart get major errors.

Nope... I guess I didn't have the motivation to do it. But I intend to do it sometime soon... maybe after my mid-sems get over. :-)

but i was still able to ping myself !! any ideas.

I tried it and it worked for me... it dropped the ping packets. Don't know how you could still ping yourself! Do you have the right entry corresponding to 127.0.0.1 in your /etc/hosts file? Or if you were connected to the internet and pinged your own machine, the packets could've originated from the dynamic ip (assuming dialup) and would've passed... not sure about this though... don't know!

actually yes and no. firstly there are two parts, packet filtering and actual rules which say what action to be performed to specific packets. packet filtering capability has to be enabled in the kernel. networking protocols etc are all specified in kernel options during compilation. during normal operation there is the iptable app which sits on top and performs various firewall operations based on the packets which the kernel gets. hrishi, correct me if i goofed in the above explanation.

You're pretty much right. In plain English, packet filtering is built into the kernel. So one could say that it is very much a part of linux. iptables is just a tool which tells the kernel what to accept and what not to... In other words, the decisions about packet filtering are made by the kernel (using the rules in the chains) and not by the program iptables. Iptables isn't a daemon...

your iit festival might have been a blast. did you participate/organise?

Nope... just enjoyed! I'm pretty lazy about these things! :-)
There was this lecture by Prof. Kevin Warwick of University of Reading, UK. Don't know if you guys have heard about him; he'd implanted a (actually 3 if I'm not wrong) chips in his hand... and became the first cyborg. It was pretty good. I'll write more about it some day.

Re: iptables

Long time no see... :-)

great to hear from you hrishi. and even better on getting some good linux tips. try and post a bit more often. maybe just links of some good resources/features on linux or anything for that matter.

there is actually so much stuff i can ask you on linux actually. did u try kernel 2.6? i tried compiling but on restart get major errors.

your iit festival might have been a blast. did you participate/organise?

Iptables is an excellent packet filtering tool.

i read up on the link you sent and tried one example from the iptables-HOWTO. the example was to disable ping by
# iptables -A INPUT -s 127.0.0.1 -p icmp -j DROP
but i was still able to ping myself !! any ideas.


Isn't a firewall a separate piece of software? Separate from Linux?

actually yes and no. firstly there are two parts, packet filtering and actual rules which say what action to be performed to specific packets. packet filtering capability has to be enabled in the kernel. networking protocols etc are all specified in kernel options during compilation. during normal operation there is the iptable app which sits on top and performs various firewall operations based on the packets which the kernel gets. hrishi, correct me if i goofed in the above explanation.

Thursday, February 19, 2004

Return of the Assertions

i was chatting with mohn , and we ended up discussing assertions again. the discussion ended with mohn suggesting disabling assertion at compile time.

i looked it up, and realised that it is not possible to disable assertions during compilation. (in java atleast). an example in javaworld, explains the point.

assertions were included in java 1.4. so all assert containing code is compiled with the flag -source 1.4 . suppose you do not include this option and try to compile code which contains the assert keyword,
Foo.java:5: warning: as of release 1.4, assert is a keyword, and may not be used as an identifier
is the error you'll get.

assert can be enabled/disabled during running code however, with the -ea , -da options.

how is it in .net ?

another question (probably the dumbest however) i had is whether FooBar is supposed ot mean anything. as i i have seen so many FooBar examples, i wonder if it was some historic programming whatever. u guys know what its supposed to signify or do i just need a break !!

Re: Code Review

please confirm what i understood. as many classes in one package get converted to one exe/dll file. also the size of these exe's/dll's must be very small comparatively. say a few 5-10kb for small apps plus some extra 10+ kb for the metadata.

Yes... many classes can be compiled down to one exe/dll. The key word is "can". You can compile each class to it's own dll if you want to and then reference those dll's in an exe.

I'm not sure about the size of the exes/dlls. For my CDPlayer app, which had 9 source code files, several images and a resource file, the exe came out to 144 kb. I'm not sure how the assembly stores the metadata exactly, but you can view it using the il disassembling tool (ildasm). But the metadata shouldn't take up too much space... I wouldn't think.

mohn told me that code on one (earlier) .net version could not be run on the newer version because of configuration file stuff. could you (mohn) explain more on this. also in .net, are certain parts of the api removed for next versions, or carried about like in java.

When you create an application with one version of the framework, your app will only run if that ver of the framework is installed. That info is contained in the exe/dll metadata. So again, taking my CDPlayer app as an ex. I created it using v 1.0. You (Rahul) have v 1.1 on your machine. So if you download my .exe and try to run it, you will get a message saying that the correct ver of the framework is not available.

Now, this is NOT to say you cannot run it on other framework versions. All I have to do is create a config file and give that to you along with the exe. When you run the exe, the CLR will look at the config file (this is done automatically), which will say that my app is compatible with v 1.1 and it will execute.

So this gives you the flexibility to limit your apps to certain versions if you want to. Only two versions of the framework have been released so far v1 and v1.1. And as far as I know there aren't any breaking changes. But in the future, if something does change, you can ensure that your app requires a certain ver of the framework to execute through config files.

Re: Code Review

In .NET, everything comes down to an assembly. That assembly - be it .exe or .dll - can contain any number of classes. You deploy and execute that. You can just copy a .exe from one machine to another and execute it. As long as the machines have the CLR, nothing else is required. No registering anything, dll hell etc...

please confirm what i understood. as many classes in one package get converted to one exe/dll file. also the size of these exe's/dll's must be very small comparatively. say a few 5-10kb for small apps plus some extra 10+ kb for the metadata.


does every new release of Java update the JVM?

i am answering with what i have experienced. in java, each 1.x version is also very major. and generally takes about a year or so for the next version. so by that time there are usually major updates in jvm performance as well. the 1.4.x (suppose) are minor updates. mostly bug fixes.

also all java code is always backward compatible. even though a particular method might be deprecated, you can still use it though it will raise an warning. also all java legacy code will work even on the latest versions. this is actually a slight point of difference between developes. because you can still use deprecated code, some do not agree with this functionality. this is more of a financial decision by sun.

mohn told me that code on one (earlier) .net version could not be run on the newer version because of configuration file stuff. could you (mohn) explain more on this. also in .net, are certain parts of the api removed for next versions, or carried about like in java.

Wednesday, February 18, 2004

Re: iptables

Anyways... another example of the high customizability of linux. I wanted to set up a custom firewall rule on my computer that would block all requests to port 80 of any server that is outside the campus. Just a one command job. Iptables is an excellent packet filtering tool with several updates over it's old cousin (or should I say ancestor) ipchains

Isn't a firewall a separate piece of software? Separate from Linux?

BTW, another spoof on google.com. Check out googirl.com.ar :-)

They seem to have made booble much more interactive.

Re: Code Review

also for gui based apps it is very odd for a cmd/shell window running in the background in which the java command was given. so there also exists a javaw command which will start the gui app without the cmd window

Java was designed with the intention of being run on set top boxes right? Then it moved to the server and applets. I suppose because of this it's not that "client friendly". How often dyou see java apps on the desktop anyway?

these problems are further magnified as in java each class is in a seperate file. (which i think is not the case for .net)

Yup, it's not the case in .NET. In java your packaging structure is interelated with your file/folder structure. That's not such a great thing. You don't have freedom to organize it the way you want. I wonder why they chose to do that.

metadata has been introduced in java 1.5. i do not know if metadata will change this scenario. mohn could tell us more on .net packaging, and probably a lot more on meta-data.

From a little I've read, the meta-data functionality in java 1.5 is basically attributes. So you can add attributes and the jvm will inject code when you compile it.

I wrote some stuff about meta-data in my prev gigantic posts on .NET. Basically, it is some info that will be used by the runtime (clr/jvm). For ex, in .NET, you can include an attribute for Serialization for a class. When you compile your code to intermediate code, the compile will also metadata saying that this class has been marked (flagged) for serialization. The runtime will inspect this metadata at run-time and automatically serialize your class when you want it to. This is something the runtime itself implements. You can also include your own custom attributes and then use reflection to inspect it.

In .NET, everything comes down to an assembly. That assembly - be it .exe or .dll - can contain any number of classes. You deploy and execute that. You can just copy a .exe from one machine to another and execute it. As long as the machines have the CLR, nothing else is required. No registering anything, dll hell etc...

Probably a dumb question... but does every new release of Java update the JVM? Or is it just the class library that gets updated? For java 1.5, I'm pretty sure with attribute functionality, generics etc..., the jvm will have to be updated, but what about for others - like minor updates?

iptables

Long time no see... :-)

Anyways... another example of the high customizability of linux. I wanted to set up a custom firewall rule on my computer that would block all requests to port 80 of any server that is outside the campus. Just a one command job. Iptables is an excellent packet filtering tool with several updates over it's old cousin (or should I say ancestor) ipchains.

Here's a link which would give a lot of info about iptables.
http://www.linuxguruz.com/iptables/howto/

BTW, another spoof on google.com. Check out googirl.com.ar :-)

Re: Code Review

as mohn pointed out, in java jar files are used to package applications. actually jar files are just glorified zip files with a slightly different compression.

in java i can execute a jar file directly. by the command
$ java -jar MyJarApp.jar

inside the jar packages there exists a manifest file. the manifest file declares the entry-point or main method containing class. this class is executed first.

there are no exe's or dll's in java. for java apps, generally batch or/and shell files are used so that the client does not have to actually java. i have noticed many apps which provide both batch(.bat for win) and shell scripts(.sh for *nix). sometimes exe files are created which spawn java processes. but this is platform dependent.

also for gui based apps it is very odd for a cmd/shell window running in the background in which the java command was given. so there also exists a javaw command which will start the gui app without the cmd window. to try jar and javaw try the following
goto j2sdk install dir
there goto demo>>jfc>>Stylepad
$ javaw -jar Stylepad.jar

i feel that this(jar packages) is a problem for desktop apps. but for server apps its fine. these problems are further magnified as in java each class is in a seperate file. (which i think is not the case for .net). in libapp i have extensively used inner classes for all gui widget handlers. so i think the class file count reaches about 100, which is a lot.

metadata has been introduced in java 1.5. i do not know if metadata will change this scenario. mohn could tell us more on .net packaging, and probably a lot more on meta-data.

by the way, jar == java-archive. for j2ee, there also exist war and ear files. war == web-archive. a war file can be deployed within any j2ee compliant web server, and will run. war files mostly contain jsp's, servlets etc. ear == enterprise-archive. ear files can be deployed within application servers. ear files mostly contain ejb's.