This assignment is to practice C#. I am getting familiar with C# function such as Queue. What I had to do is create a simple calculator (calc) and simple finite state machine (fsm). I put the data and operation of calc and fsm into the queue, then finally I process everything inside the queue.
The hardest part of this assignment is design the queue class such that my data can goes smoothly without too many if statement.The suggestion from Ed is put a header into the queue before inserting data. So when I enqueue the data, I enqueue it twice (header and data) and dequeue it twice. But I couldn't come up with enqueue process that can just call
myQueue.Enqueue(header); -> header type is calc
myQueue.Enqueue(data); -> calc data
Then my solution is I wrapped the header and data together as the input queue. So I only enqueue and dequeue once. Here is I design the class.
interface Data {}
struct Calc_Data : Data;
struct FSM_Data : Data;
enum QueueType { QUEUE_CALC, QUEUE_FSM }
struct QueueData // the queue will accept this data
{
QueueType type;
Data data; // calc or fsm
int seqNumber;
}
class CalcQueue
{
void add( Calc_Data data )
{
inQueue.enqueue (new QueueData( QUEUE_CALC, data ));
}
}
// the same thing with fsm.
Then, the process function can do the magic.
Friday, April 26, 2013
Friday, April 19, 2013
UDP
The UDP programming is different with TCP. While in TCP we send and wait until the recipient receive the data, in UDP we can just send send send the data. No matter the recipient has received or not. In this way, it runs very fast. But the data might be broken or lost. This is unreliable.
Thursday, April 18, 2013
TCP
The third assignment is about TCP and UDP. I wanna talk about TCP first because I just finish it. So it is basically about creating a connection between client and server through a socket. The server listen from a port (ex: 8888). Basically, the server open that port and let everyone coming from that port.
From the client side, if he wants to connect to the server, he has to go through the opening port, that is 8888. So when the client connect to the server, it creates the connection socket. So next time when client wants to communicate with server and vice versa, they communicate from the socket. The process of making connection is called 3 handshake because there are 3 messages transmitted to create the connection.
Generally, this TCP assignment is easy. First of all, we create the connection between client and server. After the connection is made, client send a list of data to server. The server sort the list and send them back to client.
The hardest part is understanding the code line by line and learned what the code is actually doing. Then finally, do some coding stuffs and the TCP is done.
From the client side, if he wants to connect to the server, he has to go through the opening port, that is 8888. So when the client connect to the server, it creates the connection socket. So next time when client wants to communicate with server and vice versa, they communicate from the socket. The process of making connection is called 3 handshake because there are 3 messages transmitted to create the connection.
Generally, this TCP assignment is easy. First of all, we create the connection between client and server. After the connection is made, client send a list of data to server. The server sort the list and send them back to client.
The hardest part is understanding the code line by line and learned what the code is actually doing. Then finally, do some coding stuffs and the TCP is done.
Wednesday, April 10, 2013
serialization
Basically, serialization is bundling an object into something that can be moved to other machine. After moved to a machine, that thing is extracted into another object which is called deserialization. Overall, this assignment is easy. The hardest part is arranging the data structure so it is optimized. I use __m64 to try to optimize the data structure.
This class is the most challenging:
class Fish
{
Apple pApple;
Orange *pOrange;
union
{
// this variable can share the memory address with the int and float. It has 8 bytes
__m64 op1;
struct
{
// these variables will be shared with op1
int x;
float y;
};
};
union
{
// this integer variable also shared with chars variable
int op2;
struct
{
char a;
char pad1,pad2,pad3;
};
};
};
I was thinking to make copying process in one stamp. But I can't figure out how to do it. This is the best I can do.
This class is the most challenging:
class Fish
{
Apple pApple;
Orange *pOrange;
union
{
// this variable can share the memory address with the int and float. It has 8 bytes
__m64 op1;
struct
{
// these variables will be shared with op1
int x;
float y;
};
};
union
{
// this integer variable also shared with chars variable
int op2;
struct
{
char a;
char pad1,pad2,pad3;
};
};
};
I was thinking to make copying process in one stamp. But I can't figure out how to do it. This is the best I can do.
Wednesday, April 3, 2013
first assignment
This is like very very simple assignment. Making own upper case just play with pointer and minus it to 32 ('A' - 'a') each character and its done.
Installing the xna maybe is kinda annoying. I download xna 3 which requires visual studio 2008 but I could find visual studio 2008 anymore. So I just installed xna 4
Installing the xna maybe is kinda annoying. I download xna 3 which requires visual studio 2008 but I could find visual studio 2008 anymore. So I just installed xna 4
Subscribe to:
Posts (Atom)