All blog entries, ordered from most recent. Entry count: 1198.
# UDP Sockets: send Function Blocks
Wed
20
Jul 2011
Today I've met an interesting problem with programming UDP sockets in C++. Generally UDP protocol just sends packets (datagrams) and doesn't care whether they are successfully delivered or not. They may be dropped or arrive out of order. Destination machine can even not read them or not exist at all! So I was sure that when I have a socket created with socket(), socktype=SOCK_DGRAM and connect(), I can then send packets using send() and expect this call will always be fast.
I was sure about that until today, when I met a case where a call to send() blocked for above 3 seconds! Then I've made some experiments. It looks like sending UDP packets from my Windows XP behaves like this:
I've found a question about this problem: "when does a udp sendto() blocks ?" at StackOverflow. It looks like this behavior is caused by the system unsuccessfully trying to resolve IP address to physical MAC address with every send. But it's highly operating system dependent so we can't do much about it. We just have to keep in mind that using blocking sockets for sending UDP packets can freeze our application or thread for even several seconds with each packet sent.
13 Sep 2011 Update: I researched this issue further and it looks like it's even more specific. If the target machine was online and contacted before, but now it's offline, send() is very quick. Only if the ARP forgets the IP-MAC pair for that machine, send() blocks for such a long time with every call. It probably happens after several hours. You can also force ARP to clear the cache by issuing following console command in Windows, as Administrator: arp -d *.
# Too Low Level and Too High Level Abstraction
Fri
15
Jul 2011
Programmers fascinated by object-oriented methodology love the idea of abstraction and generalization, but others - especially those interested in data-oriented design - consider "premature generalization" as a big anti-pattern. I prefer the latter approach, so as I recently learn a little bit of Java, including Servlers and JSP, I feel terrified of how its API looks like. Let me explain...
Today an idea came to my mind that an API can be too abstract (general, universal) at low level or high level. The most abstract low-level API looks like this:
int write(void *buf, int bytes);
int read(void *buf, int bytes);
It's so general and universal that it would fit anywhere, but on the other hand it doesn't provide anything specific. It's just a very narrow pipe we have to pass all our data through. Of course this method is sometimes useful. For example that's the way we transfer data over network. But we do it using some specific protocol so it's reasonable to define a higher-level API with some objects that encapsulate concepts specific to that protocol, just like cURL implements HTTP, FTP and other network protocols on top of network sockets.
Let's compare some details from two APIs. A socket can have additional options that can be set. There are different options for different kinds of sockets and they have different types - some of them are bools, others are ints. But there is only one function to set such options - setsockopt:
int setsockopt(SOCKET s, int level, int optname, const char *optval, int optlen);
Objects in POSIX Threads API also can have additional attributes, but there are specific functions to set them, like in the example below. Which way do you prefer?
int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
int pthread_attr_setstacksize(pthread_attr_t *attr , size_t stacksize);
But excessive abstraction can also go too far the other way. That's what I see in Java API. I mean, these who code a lot in this language certainly can "feel" the sense in this approach, but for me it's almost ridiculous. Not only every part of the Java API has dozens of small classes with not much more than simple getName/setName methods and there is an interface for everything just like people were afraid of using real classes, but lots os stuff is refered by strings. I'd say Java is so high level that it's not only a strongly-typed language, it's stringly-typed language. Lots of classes implementing some interface can be registered in some global registry under its name so an instance can be constructed without ever refering to the real class, like: new SomeSpecificClass().
Probably the most grotesque example I saw today is java.naming package. Including its subpackages, it contains about hunred of classes and interfaces. But there is more than this. It's the whole great body of knowledge called JNDI (Java Naming and Directory Interface) with long tutorials and lots of concepts to understand, like Context, InitialContext, Directory, Service Provider, Lookup, Names, Composite Names, Compound Names, Naming System, Federations and so on... All this just to provide an abstract interface for a tree of any objects referred by name, so that disk files and directories can be accessed same way as data received with LDAP or some global variables defined in an XML file. Do anyone really needs that? The javax.naming.Context interface is not far from what would be the ultimate high level abstraction:
interface SuperAbstractEverything {
public Object getObject(String namePathIdOrWhatever);
};
Comments | #java #software engineering Share
# Social Graph - Application on Facebook
Mon
11
Jul 2011
If you are active Facebook user and you like data visualisation just like me, then I strongly recommend you look at Social Graph application. When you run in, a Flash applet draws circles representing all your friends and connections between them. You are not there because, well, these are your friends so you are connected to all of them. You can only see how are they connected to each other. What's most interesting though is that they form some groups, which are clearly depicted thanks to graph visualisation algorithm used in this app. For example, my graph looks like this:

Several persons are not connected to anyone other I know. They are drawn somewhere outside the graph in a far distance. These are people who I know from some unusual place or who do not participate actively in Facebook and do not collect friends.
Rest of them forms clearly distinctive groups. The group on the right are people from my home town - mostly my friends from high school or university. The biggest group in the middle are passionate game developers from warsztat.gd community. Small group at the bottom consisting of four circles are contacts from my current job. On the left of Warsztat there is a group of professional game developers from Polish game industry. And finally the smaller group on the left consists of people I know from psytrance parties :)
What's also interesting is that there are some people who play role of a "center" of some group - are connected with almost everyone else in that group. Others are "connectors" that join two groups.
Comments | #rendering #web Share
# Nyan Cat + Angry Birds = Angry Nyan Cat
Sat
09
Jul 2011
If Angry Birds was joined with Nyan Cat, how would it look like? I think it would be something like this:

Note: This is only an image I created just "for the lulz". There is no actual game like that.
Comments | #humor #games #web Share
# Google+ - Social Network from Google
Fri
01
Jul 2011
Google announced they are working on a social networking website called Google+ which is going to compete with Facebook. It looks very promising so I look forward to test it when they release the website to the public. I especially like the idea of creating "Circles" of people to share things with only some groups of friends, not everyone. I don't want to express my political and other views to everyone or, on the other hand, bother all my friends with information about programming that are understandable and interesting to only those who share my passion.
Facebook is already popular, but we all know that Google develops good products (like search engine, Gmail, Chrome, Translate and numerous other stuff) so all in all I hope Google+ will become the successor of Facecbook, not a big failure like Google Wave. I already publish my photos on Picasa not on Facebook.
# Dyskusje o polskiej branży gier
Tue
07
Jun 2011
Sprawa jest typowo polska, więc wyjątkowo napiszę po polsku. Jakiś czas temu pojawił się artykuł "Wielka bitwa o programistów: firmom z branży gier komputerowych brakuje rąk do pracy" na gazetaprawna.pl, streszczony potem jako Dziennik Gazeta Prawna: "firmom z branży gier brakuje rąk do pracy" na polygamia.pl. Ten artykuł - i nie tylko on - sprowokował w Internecie ciekawe dyskusje mniej lub bardziej anonimowych osobników obeznanych z realiami branży w Polsce. Można je przeczytać (niektóre dopiero po odpowiednim zalogowaniu):
Comments | #game industry Share
# Unofficial Firmware for Canon PowerShot A610
Wed
27
Apr 2011
I have Canon PowerShow A610 digital camera. Today I've found a unofficial, free, powerful firmware for it, as well as other models from Canon. It's called CHDK - Canon Hacker Development Kit. Installation is quite easy and totally safe - it's enought to put the software onto SD card. On Windows this can be done with CardTricks application. The firmware adds some useful features, like:
I recommend this firmware to anyone who owns a Canon camera. Mine now looks like this:
Comments | #photography #hardware Share
# Hakaton - HTML5 Programming Event
Sat
16
Apr 2011
Today I was on Hakaton - a full day event organized by Google at Warsaw University of Technology. It was actually a contest in HTML5 programming. I had no previous experience in HTML5, but as a team with two other participants we scored 2nd place out of 17, won nice backpacks and books on web design :)
The theme was "Creative Science", but as always in such contests, participants just coded different stuff. Our entry is a simulation game where creatures of different species (red, green and blue) move around and do different things. Red creatures are predators - they have to eat blue ones or else they die from starvation. Blue ones try to avoid reds, eat green plants and form couples to generate offspring. Finally, green creatures do not move - they are plants, they just grow by generating new elements. Interesting situations can emerge from such simple rules. For example, sometimes only plants remain and grow infinitely, but sometimes blue creatures consume all plants and breed to a large number. We even managed to make it interactive - you can put new creatures on the map with mouse clicks. The game is coded in HTML5 and JavaScript using <canvas>. It requires a modern web browser with support for these technologies. You can play our game online here:
What I also liked was extensive use of Twitter during the party. #hakaton was second most popular hashtag in Poland today! Some screenshots:
