Linux and Xamarin socket problems

One of the requirements I set myself for my Socket library was that it should be as robust as possible about knowing that the other end of a connection had gone away. The .net socket objects are pretty bad for this, and the only way to be certain that the connection is up is to attempt to read or write its data stream. Continue reading “Linux and Xamarin socket problems”

Fun with Sockets

Actually, not fun at all. This problem has been driving me nuts for hours.

There are some things I like about .net socket programming, but one thing that always causes horrible problems is shutting sockets down when I’ve finished with them. One way or another, I always end up having to trap some exceptions. Continue reading “Fun with Sockets”

When is a char not a char? When it’s an int.

Just discovered a curious quirk in C#’s handling of the char type. Most of the time you can just think of it as being a character type, like a single character within a string, but actually it isn’t. It has an implicit coversion to int, but not to string, so

Console.WriteLine('A' + 'B');

would produce 131. Continue reading “When is a char not a char? When it’s an int.”

FtpWebRequest bug

I’ve just run into what appears to be a bug in .net’s FtpWebRequest class. I wrote some rather inefficient code that requested the same directory listing from the server several times, and found that it hung the second or third time it made the request. After some googling, I found an explanation. It seems that it caches some of the objects it creates and retrieves them from a pool, which is fine, but if it finds that the request is identical to the existing one it doesn’t reopen the response socket, so when you try to get the response stream it hangs. It’s a simple fix in my program, just save the result of the list request, but it would make it very difficult to write something that works by polling the contents of an ftp folder.

Sorting a grid bound to a BindingList

I’ve just been trying to implement move up/down buttons on the rows of a C1Flexgrid bound to a BindingList. I can’t believe how hard going it was. You would think that telling the grid to sort itself on the column containing the sort order would do it, but it doesn’t. Despite the implications in the documentation, if you read it very carefully you realise that it always uses the sort order of the underlying BindingList, regardless of what else it has been told to do. The only way to make it resort its rows is to clear out the binding list and rebuild it in the desired order.

I finally found an explanation of how to do it on StackOverflow.