Marshal.PtrToStructure (and back again) and generic solution for endianness swapping

Reflection does seem like the only real way to accomplish what you’re after. I’ve put together some code below. It creates an attribute called EndianAttribute that can be applied at the field level on a struct. I’ve included the definition for this attribute and it’s associated enum, as well as the modifications to your code … Read more

TCP server with multiple Clients

Your client will be dispatched in different threads, so they will not intersect. You just need to add something like “DispatchMethod” where your messages will be processed. using System.Text.RegularExpressions; … if (Regex.IsMatch(bufferincmessage, Properties.Settings.Default.REQLogin, RegexOptions.IgnoreCase)) { … } else if (Regex.IsMatch(bufferincmessage, /*some of your command1*/, RegexOptions.IgnoreCase)) { … } else if (Regex.IsMatch(bufferincmessage, /*some of your command1*/, … Read more

Using select() for non-blocking sockets

The problem is that when I run them, nothing happens. The real problem is that people have been pasting stuff from Beej for years without understanding it. That’s why I don’t really like that guide; it gives large blocks of code without really explaining them in detail. You’re not reading anything and not sending anything; … Read more

Java HttpURLConnection and pooling

Do both os and is need to be flushed and closed for the underlying socket to be reusable? Closing the input stream is sufficient. You can’t flush an input stream, and flushing an output stream before close is redundant. Will connection.disconnect() close the underlying socket (and hence make it unreusable)? It ‘acts as a hint’ … Read more