I Made Krisna's Times My Way to Write the Times

15Nov/110

Counting Size of Struct in C

First, i didn't guarantee that this post will give a true answer for any problem because this conclusion just made by myself based on my observation on some codes. It's very welcome to give another opinions or answers to share more knowledge and better solution.

This post will discuss about how much a struct take a memory? because of structs is a user-defined data structures, it's size will be relative to the content that the struct stores. For beginning let's refresh our memory (brain) about two most-used primitive data types size.

  1. int (4 bytes / 32 bits)
  2. char (1 bytes / 8 bits)
17Oct/110

Draw a “stdio” BL Right-Angled Triangle C Source Code

Hello again, i've posted about drawing a square shape before. Now we're move a step ahead, drawing a simple right-angled triangle. I give this post BL code which means "Bottom-Left" because we're gonna draw right-angled triangle with the '90' placed at bottom left of the triangle.

*
**
***
****

16Oct/110

Draw a “stdio” Square Shape C Source Code

Working in a one of biggest electronics manufacturer in the world that didn't make my training comes to advanced level. I've learn again from the bottom. Of course the language used is native-C which the founder passed away recently...

One of the simplest thing is using looping for drawing some shapes and in this post it will be a square shapes. The easiest shape i think. What we nee d just a nested loop for drawing the rows (outer loop) and the cell or column (inner loop) which loop with the same number (square has same size for width/column and height/row).

9Sep/111

Writing Object to XML using XmlSerializer C# Source Code

How to write an object to a file with XML format? There is a class from .NET System.Xml.Serialization.XmlSerializer which can help to completely serialize the objects from program to a XML formatted files.

Suppose that we want to save the data of a person which has attributes:

  1. Name
  2. Age
  3. Height
  4. Weight

And the Person class:

public class Person
{
    public string name;
    public int age;
    public int height;
    public int weight;

    public Person() { }

    public Person(string name, int age, int h, int w)
    {
        this.name   = name;
        this.age    = age;
        this.height = h;
        this.weight = w;
    }
}
19Aug/115

Simple HTTP Proxy Server C# Source Code

This time my next step for building the M-NIC Projects, creating a HTTP Proxy Server which is actually just an HTTP Relay :D. The concept just take everything from applications which HTTP Proxy server is set to my application then relaying the request to the destination server then relay again the response from destination server to client application.

The method? Just ordinary Socket Programming in C# (System.Net) Socket.Send(), Socket.Receive(), etc. First let's take a look to the Server Listener, every server must listen to the incoming client connection. In this application, i'm using TcpListener for that.

using System.Net;
using System.Net.Sockets;

namespace SimpleHttpProxy
{
    class ServerListerner
    {
        private int listenPort;
        private TcpListener listener;

        public ServerListerner(int port)
        {
            this.listenPort = port;
            this.listener = new TcpListener(IPAddress.Any, this.listenPort);
        }

        public void StartServer()
        {
            this.listener.Start();
        }

        public void AcceptConnection()
        {
            Socket newClient = this.listener.AcceptSocket();
            ClientConnection client = new ClientConnection(newClient);
            client.StartHandling();
        }

    }
}

How it works? See the main method implementation below. Just initiate server listener object which is listen to port 9000 (this port number is up to you, but make sure you're choosing free port number), then start the server to make the server ready to accept incoming connection and do the magic loop (actually just an infinite looping) to accept the incoming connection.