diff --git a/simics-workspace/modules/afdxES/packet-frame.dml b/simics-workspace/modules/afdxES/packet-frame.dml
index 86b19f5..18f6536 100644
--- a/simics-workspace/modules/afdxES/packet-frame.dml
+++ b/simics-workspace/modules/afdxES/packet-frame.dml
@@ -12,7 +12,7 @@ import "sample-frame.dml";

 extern void a664module_send_to_a664card(void *buf, int len);
 extern void *get_ima_server_socket(void);
-extern void ima_socket_send(void *sendbuf, int size, void *socketfd);
+extern void ima_socket_send(void *sendbuf, int size, void *socketfd, int addr_type);

 data bool init_send_time;

@@ -365,7 +365,7 @@ event send_phy {
                         $phyA.ieee_802_3_mac.send_frame(cast(&item.frame, uint8*), item.size);
                         break;
                     case ToIMAMiddleware:
-                        ima_socket_send(&item.frame, item.size, get_ima_server_socket());
+                        ima_socket_send(&item.frame, item.size, get_ima_server_socket(), 0);
                         break;
                     default:
                         log "error" : "Danger!!! Please check your work mode!";
@@ -399,7 +399,7 @@ event send_phy {
                         $phyB.ieee_802_3_mac.send_frame(cast(&item.frame, uint8*), item.size);
                         break;
                     case ToIMAMiddleware:
-                        ima_socket_send(&item.frame, item.size, get_ima_server_socket());
+                        ima_socket_send(&item.frame, item.size, get_ima_server_socket(), 0);
                         break;
                     default:
                         log "error" : "Danger!!! Please check your work mode!";
@@ -439,7 +439,7 @@ event send_phy {
                         $phyA.ieee_802_3_mac.send_frame(cast(&item.frame, uint8*), item.size);
                         break;
                     case ToIMAMiddleware:
-                        ima_socket_send(&item.frame, item.size, get_ima_server_socket());
+                        ima_socket_send(&item.frame, item.size, get_ima_server_socket(), 0);
                         break;
                     default:
                         log "error" : "Danger!!! Please check your work mode!";
@@ -461,7 +461,7 @@ event send_phy {
                         $phyB.ieee_802_3_mac.send_frame(cast(&item2.frame, uint8*), item2.size);
                         break;
                     case ToIMAMiddleware:
-                        ima_socket_send(&item2.frame, item2.size, get_ima_server_socket());
+                        ima_socket_send(&item2.frame, item2.size, get_ima_server_socket(), 0);
                         break;
                     default:
                         log "error" : "Danger!!! Please check your work mode!";
diff --git a/simics-workspace/modules/afdxES/queue.dml b/simics-workspace/modules/afdxES/queue.dml
index 692469d..b5d847b 100644
--- a/simics-workspace/modules/afdxES/queue.dml
+++ b/simics-workspace/modules/afdxES/queue.dml
@@ -40,7 +40,7 @@ method DeQueue(Queue *queue, Item *item) {
 }

 method IsEmpty(Queue *queue) -> (bool result) {
-	result = queue->front == queue->rear;
+	result = queue->item_num == 0;
 }

 method SetEmpty(Queue *queue) {
diff --git a/simics-workspace/modules/afdxES/scence3-ima-data-exchange.c b/simics-workspace/modules/afdxES/scence3-ima-data-exchange.c
index 8778eeb..101565f 100644
--- a/simics-workspace/modules/afdxES/scence3-ima-data-exchange.c
+++ b/simics-workspace/modules/afdxES/scence3-ima-data-exchange.c
@@ -25,7 +25,18 @@ typedef enum {
     READY_TO_RECV_FRAME,
     BEGIN_TO_HANDLE_FRAME
 } RECV_STATE;
+
+typedef enum {
+    IMA_SERVER_INIT_ADDR,
+    IMA_CLIENT_INIT_ADDR
+} ADDR_TYPE;

+#ifndef __TCP__
+struct sockaddr_in ima_server_init_addr;
+struct sockaddr_in ima_client_init_addr;
+#else
+#endif
+
 int ima_server_socket_init(int portNum) {
     WSADATA wsa;

@@ -33,32 +44,54 @@ int ima_server_socket_init(int portNum) {
         fprintf(stderr, "WSAStartup failed, error code is %d.\n", WSAGetLastError());
         exit(1);
     }
-
+#ifdef __TCP__
     SOCKET serSocket = socket(AF_INET, SOCK_STREAM, 0);
-
+#else
+    SOCKET serSocket = socket(AF_INET, SOCK_DGRAM, 0);
+#endif
+
     if (serSocket == INVALID_SOCKET) {
         fprintf(stderr, "Create server socket failed, error code is %d.\n", WSAGetLastError());
         exit(1);
     }
-
+
+#ifdef __TCP__
     SOCKADDR_IN addr;
     addr.sin_family = AF_INET;
     addr.sin_addr.s_addr = htonl(INADDR_ANY);
     addr.sin_port = htons(portNum);
-
+#else
+    struct sockaddr_in addr;
+    addr.sin_family = AF_INET;
+    addr.sin_addr.s_addr = INADDR_ANY;
+    addr.sin_port = htons(portNum);
+    ima_server_init_addr = addr; /* ok? */
+#endif
+
     int opt = 1;
     setsockopt(serSocket, SOL_SOCKET, SO_REUSEADDR, (const char*)(&opt), sizeof(opt));

+#ifdef __TCP__
     if (bind(serSocket, (SOCKADDR*)&addr, sizeof(SOCKADDR_IN)) == SOCKET_ERROR) {
         fprintf(stderr, "Bind failed, error code is %d\n", WSAGetLastError());
         exit(1);
     }
-
+#else
+    if (bind(serSocket, (struct sockaddr *)&addr, sizeof(addr)) == SOCKET_ERROR) {
+        printf ("Bind failed with error code: %d\n", WSAGetLastError());
+        exit(EXIT_FAILURE);
+    }
+#endif
+
+#ifdef __TCP__
     if (listen(serSocket, 1) == SOCKET_ERROR) {
         fprintf(stderr, "Listen failed, error code is %d\n", WSAGetLastError());
         exit(1);
     }
+#else
+#endif

+#ifdef __TCP__
     SOCKADDR_IN clientsocket;
     int len = sizeof(SOCKADDR_IN);

@@ -66,7 +99,9 @@ int ima_server_socket_init(int portNum) {
         fprintf(stderr, "Accept failed, error code is %d.\n", WSAGetLastError());
         exit(1);
     }
-
+#else
+#endif
+
     fprintf(stdout, "Socket_server_init ok\n");

     return 0;
@@ -80,24 +115,40 @@ int ima_client_socket_init(int portNum) {
         exit(1);
     }

-    ima_client_socket = socket(AF_INET, SOCK_STREAM, 0);
-
+#ifdef __TCP__
+    ima_client_socket = socket(AF_INET, SOCK_STREAM, 0);
+#else
+    ima_client_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+#endif
+
     if (ima_client_socket  == INVALID_SOCKET) {
         fprintf(stderr, "Create client socket failed, error code is %d.\n", WSAGetLastError());
         exit(1);
     }

+#ifdef __TCP__
     SOCKADDR_IN serveraddr;
     memset(&serveraddr, 0, sizeof(serveraddr));
     serveraddr.sin_family = AF_INET;
     serveraddr.sin_port = htons(portNum);
     serveraddr.sin_addr.s_addr = inet_addr("127.0.0.1");
-
+#else
+    struct sockaddr_in server;
+    memset((char*)&server, 0, sizeof(server));
+    server.sin_family = AF_INET;
+    server.sin_port = htons(portNum);
+    server.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
+    ima_client_init_addr = server; /* ok? */
+#endif
+
+#ifdef __TCP__
     if (connect(ima_client_socket, (struct sockaddr *) &serveraddr, sizeof(serveraddr)) == SOCKET_ERROR) {
         fprintf(stderr, "Connect failed, error code is %d.\n", WSAGetLastError());
         exit(1);
     }
-
+#else
+#endif
+
     unsigned long ul = 1;
     if (ioctlsocket(ima_client_socket, FIONBIO, (unsigned long*)&ul) == SOCKET_ERROR) {
         fprintf(stderr, "ioctlsocket failed, error code is %d\n", WSAGetLastError());
@@ -109,14 +160,39 @@ int ima_client_socket_init(int portNum) {
     return 0;
 }

-void ima_socket_send(void *sendbuf, int size, void *socketfd) {
+void ima_socket_send(void *sendbuf, int size, void *socketfd, int addr_type) {
+    struct sockaddr_in addr;
+    switch (addr_type) {
+        case IMA_SERVER_INIT_ADDR:
+            addr = ima_server_init_addr;
+            break;
+        case IMA_CLIENT_INIT_ADDR:
+            addr = ima_client_init_addr;
+            break;
+        default:
+            fprintf(stderr, "Fatal error: unkown addr type!\n");
+            break;
+    }
+
+#ifdef __TCP__
     if (send(*(SOCKET*)socketfd, (char *)&size, sizeof(size), 0) != sizeof(size)) {
         fprintf(stderr, "Socket send failed, error code is %d\n", WSAGetLastError());
     }

     if (send(*(SOCKET*)socketfd, (char *)sendbuf, size, 0) != size) {
         fprintf(stderr, "Socket send failed, error code is %d\n", WSAGetLastError());
-    }
+    }
+#else
+    if (sendto(*(SOCKET*)socketfd, (char *)&size, sizeof(size),
+               0, (struct socketaddr *)&addr, sizeof(addr)) != sizeof(size)) {
+        fprintf(stderr, "sendto() failed with error code: %d\n", WSAGetLastError());
+    }
+
+    if (sendto(*(SOCKET*)socketfd, (char *)sendbuf, size,
+               0, (struct socketaddr *)&addr, sizeof(addr)) != size) {
+        fprintf(stderr, "sendto() failed with error code: %d\n", WSAGetLastError());
+    }
+#endif
 }

 static int chars_to_int(char *array) {
@@ -128,14 +204,38 @@ static int chars_to_int(char *array) {
     return ret;
 }

-int ima_socket_recv(void *recvbuf, int size, void *socketfd) {
+int ima_socket_recv(void *recvbuf, int size, void *socketfd, int addr_type) { /* 最后一个参数用作数组下标也不错 */
+    struct sockaddr_in addr;
+    switch (addr_type) {
+        case IMA_SERVER_INIT_ADDR:
+            addr = ima_server_init_addr;
+            break;
+        case IMA_CLIENT_INIT_ADDR:
+            addr = ima_client_init_addr;
+            break;
+        default:
+            fprintf(stderr, "Fatal error: unkown addr type!\n");
+            break;
+    }
+    int addr_len = sizeof(addr);
+
     if (recv_state == WAIT_FOR_FRAME_SIZE) {
         char frame_size[4];
+#ifdef __TCP__
         int ret = recv(*(SOCKET*)socketfd, (char*)&frame_size, 4, 0);
+#else
+        int ret = recvfrom(*(SOCKET*)socketfd, (char*)&frame_size, 4, 0,
+                           (struct socketaddr *)&addr, &addr_len); /* notice here */
+#endif
         if (ret > 0) {
             if (ret != 4) {
                 while (4 - ret) {
+#ifdef __TCP__
                     int ret1 = recv(*(SOCKET*)socketfd, frame_size + ret, 4 - ret, 0);
+#else
+                    int ret1 = recvfrom(*(SOCKET*)socketfd, frame_size + ret, 4 - ret, 0,
+                                        (struct socketaddr *)&addr, &addr_len); /* notice here */
+#endif
                     if (ret1 > 0) {
                         ret += ret1;
                     } else {
@@ -152,7 +252,7 @@ int ima_socket_recv(void *recvbuf, int size, void *socketfd) {

             recv_state = READY_TO_RECV_FRAME;

-            return ima_socket_recv(recvbuf, chars_to_int((char*)&frame_size), socketfd);
+            return ima_socket_recv(recvbuf, chars_to_int((char*)&frame_size), socketfd, addr_type);
         } else {
             switch (WSAGetLastError()) {
                 case WSAEWOULDBLOCK:
@@ -163,11 +263,21 @@ int ima_socket_recv(void *recvbuf, int size, void *socketfd) {
             }
         }
     } else if (recv_state == READY_TO_RECV_FRAME) {
+#ifdef __TCP__
         int ret = recv(*(SOCKET*)socketfd, (char*)&frame, size, 0);
+#else
+        int ret = recvfrom(*(SOCKET*)socketfd, (char*)&frame, size, 0,
+                           (struct socketaddr *)&addr, &addr_len); /* notice here */
+#endif
         if (ret > 0) {
             if (ret != size) {
                 while (size - ret) {
+#ifdef __TCP__
                     int ret1 = recv(*(SOCKET*)socketfd, frame + ret, size - ret, 0);
+#else
+                    int ret1 = recvfrom(*(SOCKET*)socketfd, frame + ret, size - ret, 0,
+                                        (struct socketaddr *)&addr, &addr_len); /* notice here */
+#endif
                     if (ret1 > 0) {
                         ret += ret1;
                     } else {
@@ -183,7 +293,7 @@ int ima_socket_recv(void *recvbuf, int size, void *socketfd) {
             }

             recv_state = BEGIN_TO_HANDLE_FRAME;
-            return ima_socket_recv(recvbuf, size, NULL);
+            return ima_socket_recv(recvbuf, size, NULL, addr_type);
         } else {
             switch (WSAGetLastError()) {
                 case WSAEWOULDBLOCK:
diff --git a/simics-workspace/modules/afdxES/scence3-ima-data-exchange.dml b/simics-workspace/modules/afdxES/scence3-ima-data-exchange.dml
index 7ac783e..15d7bf1 100644
--- a/simics-workspace/modules/afdxES/scence3-ima-data-exchange.dml
+++ b/simics-workspace/modules/afdxES/scence3-ima-data-exchange.dml
@@ -3,7 +3,7 @@ dml 1.2;
 extern int ima_server_socket_init(int portNum);
 extern int ima_client_socket_init(int portNum);
 extern void *get_ima_client_socket(void);
-extern int ima_socket_recv(void *recvbuf, int size, void *socketfd);
+extern int ima_socket_recv(void *recvbuf, int size, void *socketfd, int addr_type);
 extern int get_recv_state(void);
 extern void change_recv_state(void);

@@ -37,7 +37,7 @@ method init_ima_recv() {
     if ($middleware_mode == ToIMAMiddleware) {
         if ($is_cfg_done) {
             local uint8 data[MAX_FRAME_SIZE];
-            $size = ima_socket_recv(&data, $size, get_ima_client_socket());
+            $size = ima_socket_recv(&data, $size, get_ima_client_socket(), 1);
             if (($size != 0) && (get_recv_state() == 2)) {
                 change_recv_state();
                 call $recv_frame(data, $size);
diff --git a/simics-workspace/modules/afdxES/scence3-ima-data-exchange.h b/simics-workspace/modules/afdxES/scence3-ima-data-exchange.h
index ed7a4e7..12b0aee 100644
--- a/simics-workspace/modules/afdxES/scence3-ima-data-exchange.h
+++ b/simics-workspace/modules/afdxES/scence3-ima-data-exchange.h
@@ -10,7 +10,7 @@ extern SOCKET ima_server_socket;

 extern int ima_server_socket_init(int portNum);
 extern int ima_client_socket_init(int portNum);
-extern int ima_socket_recv(unsigned char *recvbuf, int size, void *socketfd);
-extern int ima_socket_send(unsigned char *sendbuf, int size, void *socketfd);
+extern int ima_socket_recv(unsigned char *recvbuf, int size, void *socketfd, int addr_type);
+extern int ima_socket_send(unsigned char *sendbuf, int size, void *socketfd, int addr_type);
 extern void *get_ima_client_socket(void);
 extern void *get_ima_server_socket(void);
diff --git a/simics-workspace/modules/afdxES/scence3-ima-data-exchange.c b/simics-workspace/modules/afdxES/scence3-ima-data-exchange.c
index 101565f..f4c51a6 100644
--- a/simics-workspace/modules/afdxES/scence3-ima-data-exchange.c
+++ b/simics-workspace/modules/afdxES/scence3-ima-data-exchange.c
@@ -3,20 +3,11 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <unistd.h>
-#include <WINSOCK2.H>
+#include <winsock2.h>

 SOCKET ima_client_socket = INVALID_SOCKET;
 SOCKET ima_server_socket = INVALID_SOCKET;

-/*
-#define BUFFER_SIZE          4
-#define BUFFER_MAXLENGTH      1518 * 2
-
-static char frame_buffer[BUFFER_SIZE + BUFFER_MAXLENGTH];
-static int pbegin = 0;
-static int pend = 0;
-*/
-
 static int recv_state;
 static char frame[1518];

@@ -30,14 +21,17 @@ typedef enum {
     IMA_SERVER_INIT_ADDR,
     IMA_CLIENT_INIT_ADDR
 } ADDR_TYPE;
-
+
+#define SERVER_IP "127.0.0.1"
+#define CLIENT_IP "127.0.0.1"
+
 #ifndef __TCP__
 struct sockaddr_in ima_server_init_addr;
 struct sockaddr_in ima_client_init_addr;
 #else
 #endif

-int ima_server_socket_init(int portNum) {
+int ima_server_socket_init(int serverPortNum, int clientPortNum) {
     WSADATA wsa;

     if (WSAStartup(MAKEWORD(2,2), &wsa)) {
@@ -59,13 +53,19 @@ int ima_server_socket_init(int portNum) {
     SOCKADDR_IN addr;
     addr.sin_family = AF_INET;
     addr.sin_addr.s_addr = htonl(INADDR_ANY);
-    addr.sin_port = htons(portNum);
+    addr.sin_port = htons(serverPortNum);
 #else
     struct sockaddr_in addr;
     addr.sin_family = AF_INET;
     addr.sin_addr.s_addr = INADDR_ANY;
-    addr.sin_port = htons(portNum);
-    ima_server_init_addr = addr; /* ok? */
+    addr.sin_port = htons(serverPortNum);
+
+	struct sockaddr_in clientaddr;;
+    clientaddr.sin_family = AF_INET;
+    clientaddr.sin_addr.S_un.S_addr = inet_addr(CLIENT_IP);
+    clientaddr.sin_port = htons(clientPortNum);
+
+    ima_server_init_addr = clientaddr;
 #endif

     int opt = 1;
@@ -100,6 +100,7 @@ int ima_server_socket_init(int portNum) {
         exit(1);
     }
 #else
+    ima_server_socket = serSocket;
 #endif

     fprintf(stdout, "Socket_server_init ok\n");
@@ -107,7 +108,7 @@ int ima_server_socket_init(int portNum) {
     return 0;
 }

-int ima_client_socket_init(int portNum) {
+int ima_client_socket_init(int clientPortNum, int serverPortNum) {
     WSADATA wsa;

     if (WSAStartup(MAKEWORD(2,2), &wsa)) {
@@ -130,15 +131,16 @@ int ima_client_socket_init(int portNum) {
     SOCKADDR_IN serveraddr;
     memset(&serveraddr, 0, sizeof(serveraddr));
     serveraddr.sin_family = AF_INET;
-    serveraddr.sin_port = htons(portNum);
+    serveraddr.sin_port = htons(clientPortNum);
     serveraddr.sin_addr.s_addr = inet_addr("127.0.0.1");
 #else
-    struct sockaddr_in server;
-    memset((char*)&server, 0, sizeof(server));
-    server.sin_family = AF_INET;
-    server.sin_port = htons(portNum);
-    server.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
-    ima_client_init_addr = server; /* ok? */
+    struct sockaddr_in serveraddr;
+    memset((char*)&serveraddr, 0, sizeof(serveraddr));
+    serveraddr.sin_family = AF_INET;
+    serveraddr.sin_port = htons(serverPortNum);
+    serveraddr.sin_addr.S_un.S_addr = inet_addr(SERVER_IP);
+
+    ima_client_init_addr = serveraddr;
 #endif

 #ifdef __TCP__
@@ -147,8 +149,17 @@ int ima_client_socket_init(int portNum) {
         exit(1);
     }
 #else
+    struct sockaddr_in addr;
+    addr.sin_family = AF_INET;
+    addr.sin_addr.s_addr = INADDR_ANY;
+    addr.sin_port = htons(clientPortNum);
+
+    if (bind(ima_client_socket, (struct sockaddr *)&addr, sizeof(addr)) == SOCKET_ERROR) {
+        printf ("Bind failed with error code: %d\n", WSAGetLastError());
+        exit(EXIT_FAILURE);
+    }
 #endif
-
+
     unsigned long ul = 1;
     if (ioctlsocket(ima_client_socket, FIONBIO, (unsigned long*)&ul) == SOCKET_ERROR) {
         fprintf(stderr, "ioctlsocket failed, error code is %d\n", WSAGetLastError());
@@ -184,12 +195,12 @@ void ima_socket_send(void *sendbuf, int size, void *socketfd, int addr_type) {
     }
 #else
     if (sendto(*(SOCKET*)socketfd, (char *)&size, sizeof(size),
-               0, (struct socketaddr *)&addr, sizeof(addr)) != sizeof(size)) {
+               0, (struct sockaddr *)&addr, sizeof(addr)) != sizeof(size)) {
         fprintf(stderr, "sendto() failed with error code: %d\n", WSAGetLastError());
     }

     if (sendto(*(SOCKET*)socketfd, (char *)sendbuf, size,
-               0, (struct socketaddr *)&addr, sizeof(addr)) != size) {
+               0, (struct sockaddr *)&addr, sizeof(addr)) != size) {
         fprintf(stderr, "sendto() failed with error code: %d\n", WSAGetLastError());
     }
 #endif
@@ -225,7 +236,7 @@ int ima_socket_recv(void *recvbuf, int size, void *socketfd, int addr_type) { /*
         int ret = recv(*(SOCKET*)socketfd, (char*)&frame_size, 4, 0);
 #else
         int ret = recvfrom(*(SOCKET*)socketfd, (char*)&frame_size, 4, 0,
-                           (struct socketaddr *)&addr, &addr_len); /* notice here */
+                           (struct sockaddr *)&addr, &addr_len); /* notice here */
 #endif
         if (ret > 0) {
             if (ret != 4) {
@@ -234,7 +245,7 @@ int ima_socket_recv(void *recvbuf, int size, void *socketfd, int addr_type) { /*
                     int ret1 = recv(*(SOCKET*)socketfd, frame_size + ret, 4 - ret, 0);
 #else
                     int ret1 = recvfrom(*(SOCKET*)socketfd, frame_size + ret, 4 - ret, 0,
-                                        (struct socketaddr *)&addr, &addr_len); /* notice here */
+                                        (struct sockaddr *)&addr, &addr_len); /* notice here */
 #endif
                     if (ret1 > 0) {
                         ret += ret1;
@@ -267,7 +278,7 @@ int ima_socket_recv(void *recvbuf, int size, void *socketfd, int addr_type) { /*
         int ret = recv(*(SOCKET*)socketfd, (char*)&frame, size, 0);
 #else
         int ret = recvfrom(*(SOCKET*)socketfd, (char*)&frame, size, 0,
-                           (struct socketaddr *)&addr, &addr_len); /* notice here */
+                           (struct sockaddr *)&addr, &addr_len); /* notice here */
 #endif
         if (ret > 0) {
             if (ret != size) {
@@ -276,7 +287,7 @@ int ima_socket_recv(void *recvbuf, int size, void *socketfd, int addr_type) { /*
                     int ret1 = recv(*(SOCKET*)socketfd, frame + ret, size - ret, 0);
 #else
                     int ret1 = recvfrom(*(SOCKET*)socketfd, frame + ret, size - ret, 0,
-                                        (struct socketaddr *)&addr, &addr_len); /* notice here */
+                                        (struct sockaddr *)&addr, &addr_len); /* notice here */
 #endif
                     if (ret1 > 0) {
                         ret += ret1;
diff --git a/simics-workspace/modules/afdxES/scence3-ima-data-exchange.dml b/simics-workspace/modules/afdxES/scence3-ima-data-exchange.dml
index 15d7bf1..c0108fc 100644
--- a/simics-workspace/modules/afdxES/scence3-ima-data-exchange.dml
+++ b/simics-workspace/modules/afdxES/scence3-ima-data-exchange.dml
@@ -1,7 +1,7 @@
 dml 1.2;

-extern int ima_server_socket_init(int portNum);
-extern int ima_client_socket_init(int portNum);
+extern int ima_server_socket_init(int serverPortNum, int clientPortNum);
+extern int ima_client_socket_init(int clientPortNum, int serverPortNum);
 extern void *get_ima_client_socket(void);
 extern int ima_socket_recv(void *recvbuf, int size, void *socketfd, int addr_type);
 extern int get_recv_state(void);
@@ -18,14 +18,14 @@ method init_ima_send() {
         case CLIENT:
             clientPortNum = 6789;
             serverPortNum = 9876;
-            ima_client_socket_init(clientPortNum);
-            ima_server_socket_init(serverPortNum);
+            ima_client_socket_init(clientPortNum, serverPortNum);
+            ima_server_socket_init(serverPortNum, clientPortNum);
             break;
         case SERVER:
             serverPortNum = 6789;
             clientPortNum = 9876;
-            ima_server_socket_init(serverPortNum);
-            ima_client_socket_init(clientPortNum);
+            ima_server_socket_init(serverPortNum, clientPortNum);
+            ima_client_socket_init(clientPortNum, serverPortNum);
             break;
         defaut:
             break;
diff --git a/simics-workspace/modules/afdxES/scence3-ima-data-exchange.h b/simics-workspace/modules/afdxES/scence3-ima-data-exchange.h
index 12b0aee..e8c6aa4 100644
--- a/simics-workspace/modules/afdxES/scence3-ima-data-exchange.h
+++ b/simics-workspace/modules/afdxES/scence3-ima-data-exchange.h
@@ -3,13 +3,13 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <unistd.h>
-#include <WINSOCK2.H>
+#include <winsock2.h>

 extern SOCKET ima_client_socket;
 extern SOCKET ima_server_socket;

-extern int ima_server_socket_init(int portNum);
-extern int ima_client_socket_init(int portNum);
+extern int ima_server_socket_init(int serverPortNum, int clientPortNum);
+extern int ima_client_socket_init(int clientPortNum, int serverPortNum);
 extern int ima_socket_recv(unsigned char *recvbuf, int size, void *socketfd, int addr_type);
 extern int ima_socket_send(unsigned char *sendbuf, int size, void *socketfd, int addr_type);
 extern void *get_ima_client_socket(void);
diff --git a/simics-workspace/modules/afdxES/packet-frame.dml b/simics-workspace/modules/afdxES/packet-frame.dml
index 18f6536..f399ff2 100644
--- a/simics-workspace/modules/afdxES/packet-frame.dml
+++ b/simics-workspace/modules/afdxES/packet-frame.dml
@@ -354,7 +354,7 @@ event send_phy {
                     }

                     if ($enable_sample_frame) {
-                        $sample_frame_module.sample_frame.sample_frame(cast(&item.frame, uint8*), item.size);
+                        $sample_frame_module.sample_frame.sample_frame(cast(&item.frame, uint8*), item.size, 0);
                     }

                     switch ($middleware_mode) {
@@ -388,7 +388,7 @@ event send_phy {
                     }

                     if ($enable_sample_frame) {
-                        $sample_frame_module.sample_frame.sample_frame(cast(&item.frame, uint8*), item.size);
+                        $sample_frame_module.sample_frame.sample_frame(cast(&item.frame, uint8*), item.size, 0);
                     }

                     switch ($middleware_mode) {
@@ -428,7 +428,7 @@ event send_phy {
 					call $crc_check(item.frame,item.size,$Table);

                     if ($enable_sample_frame) {
-                        $sample_frame_module.sample_frame.sample_frame(cast(&item.frame, uint8*), item.size);
+                        $sample_frame_module.sample_frame.sample_frame(cast(&item.frame, uint8*), item.size, 0);
                     }

                     switch ($middleware_mode) {
@@ -450,7 +450,7 @@ event send_phy {
 					call $crc_check(item2.frame,item2.size,$Table);

                     if ($enable_sample_frame) {
-                        $sample_frame_module.sample_frame.sample_frame(cast(&item.frame, uint8*), item.size);
+                        $sample_frame_module.sample_frame.sample_frame(cast(&item.frame, uint8*), item.size, 0);
                     }

                     switch ($middleware_mode) {
diff --git a/simics-workspace/modules/afdxES/rm-handler.dml b/simics-workspace/modules/afdxES/rm-handler.dml
index 72eb325..1519f51 100644
--- a/simics-workspace/modules/afdxES/rm-handler.dml
+++ b/simics-workspace/modules/afdxES/rm-handler.dml
@@ -42,6 +42,10 @@ method recv_frame(uint8 *data, uint32 size) {
     local uint8 rm_index;
     local bool is_crc_ok;
     local RM_INFO rm_info;
+
+    if ($enable_sample_frame) {
+        $sample_frame_module.sample_frame.sample_frame(cast(&item.frame, uint8*), item.size, 1);
+    }

     if ($is_ieee_802_3_log_on) {
         call $print_ieee_802_3_mac_begin();
diff --git a/simics-workspace/modules/sample-frame-module/sample-frame-module.dml b/simics-workspace/modules/sample-frame-module/sample-frame-module.dml
index 4ae5221..9ce8065 100644
--- a/simics-workspace/modules/sample-frame-module/sample-frame-module.dml
+++ b/simics-workspace/modules/sample-frame-module/sample-frame-module.dml
@@ -12,11 +12,11 @@ import "sample-frame.dml";

 extern void init_frame_image(void);
 extern void fint_frame_image(void);
-extern void save_frame_into_disk(void *frame, void *frame_size);
+extern void save_frame_into_disk(void *frame, void *frame_size, int frame_type);

 implement sample_frame {
-    method sample_frame(uint8 *frame, uint32 frame_size) {
-        save_frame_into_disk(frame, &frame_size);
+    method sample_frame(uint8 *frame, uint32 frame_size, int frame_type) {
+        save_frame_into_disk(frame, &frame_size, frame_type);
     }
 }

diff --git a/simics-workspace/modules/sample-frame-module/save_frame_into_disk.c b/simics-workspace/modules/sample-frame-module/save_frame_into_disk.c
index 8a547ed..fc75bae 100644
--- a/simics-workspace/modules/sample-frame-module/save_frame_into_disk.c
+++ b/simics-workspace/modules/sample-frame-module/save_frame_into_disk.c
@@ -3,15 +3,25 @@

 typedef unsigned int uint32;

-FILE *frame_image;
-const char *filename = "frame_image.bin";
+typedef enum {
+    SEND,
+    RECV
+} FRAME_TYPE;
+
+FILE *frame_image[2];
+
+const char *filename[] = {
+    "sframe_image.bin"
+    "rframe_image.bin"
+};
+
 const int max_file_size = 4096 * 1024;

-static int get_file_size(void) {
+static int get_file_size(int frame_type) {
     struct stat file_stats;
     int file_size = 0;

-    if (stat(filename, &file_stats)) {
+    if (stat(filename[frame_type], &file_stats)) {
         fprintf(stderr, "File doesn't exsit.\n");
         file_size = -1;
     } else {
@@ -21,8 +31,8 @@ static int get_file_size(void) {
     return file_size;
 }

-void save_frame_into_disk(void *frame, void *frame_size) {
-    int file_size = get_file_size();
+void save_frame_into_disk(void *frame, void *frame_size, int frame_type) {
+    int file_size = get_file_size(frame_type);

     if ((file_size != -1) && (file_size >= max_file_size)) {
         fseek(frame_image, 0, SEEK_SET);
@@ -30,14 +40,16 @@ void save_frame_into_disk(void *frame, void *frame_size) {
         fseek(frame_image, 0, SEEK_END);
     }

-    fwrite(frame_size, sizeof(*(uint32*)frame_size), 1, frame_image);
-    fwrite(frame, *(uint32*)frame_size, 1, frame_image);
+    fwrite(frame_size, sizeof(*(uint32*)frame_size), 1, frame_image[frame_type]);
+    fwrite(frame, *(uint32*)frame_size, 1, frame_image[frame_type]);
 }

 void init_frame_image(void) {
-    frame_image = fopen(filename, "wb");
+    frame_image[0] = fopen(filename[0], "wb");
+    frame_image[1] = fopen(filename[1], "wb");
 }

 void fini_frame_image(void) {
-    fclose(frame_image);
+    fclose(frame_image[0]);
+    fclose(frame_image[1]);
 }
diff --git a/simics-workspace/include/sample-frame.dml b/simics-workspace/include/sample-frame.dml
index ac287bb..bdb65ee 100644
--- a/simics-workspace/include/sample-frame.dml
+++ b/simics-workspace/include/sample-frame.dml
@@ -1,5 +1,5 @@
 dml 1.2;

 typedef struct {
-    void (*sample_frame)(conf_object_t *obj, uint8 *frame, uint32 frame_size);
+    void (*sample_frame)(conf_object_t *obj, uint8 *frame, uint32 frame_size, int frame_type);
 } sample_frame_interface_t;
diff --git a/simics-workspace/modules/afdxES/rm-handler.dml b/simics-workspace/modules/afdxES/rm-handler.dml
index 1519f51..6c90715 100644
--- a/simics-workspace/modules/afdxES/rm-handler.dml
+++ b/simics-workspace/modules/afdxES/rm-handler.dml
@@ -44,7 +44,7 @@ method recv_frame(uint8 *data, uint32 size) {
     local RM_INFO rm_info;

     if ($enable_sample_frame) {
-        $sample_frame_module.sample_frame.sample_frame(cast(&item.frame, uint8*), item.size, 1);
+        $sample_frame_module.sample_frame.sample_frame(cast(data, uint8*), size, 1);
     }

     if ($is_ieee_802_3_log_on) {
diff --git a/simics-workspace/modules/sample-frame-module/parse_frame.c b/simics-workspace/modules/sample-frame-module/parse_frame.c
deleted file mode 100644
index 428e295..0000000
--- a/simics-workspace/modules/sample-frame-module/parse_frame.c
+++ /dev/null
@@ -1,62 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-
-const char *infilename = "";
-const char *outfilename = "";
-
-typedef enum {
-    DESTINATION_ADDRESS_SIZE = 6,
-    SOURCE_ADDRESS_SIZE = 6,
-    IPV4_SIZE = 2,
-    IP_STRUCTURE_SIZE = 20,
-    UDP_STRUCTURE_SIZE = 8,
-    MAX_PAYLOAD_SIZE = 1418,
-    SN_SIZE = 1,
-    CRC_SIZE = 4
-} DOMAIN_SIZE;
-
-typedef struct {
-    int frame_size;
-    char destination_address[DESTINATION_ADDRESS_SIZE + 1];
-    char source_address[SOURCE_ADDRESS_SIZE + 1];
-    char ipv4[IPV4_SIZE + 1];
-    char ip_structure[IP_STRUCTURE_SIZE + 1];
-    char udp_structure[UDP_STRUCTURE_SIZE + 1];
-    char afdxES_payload[MAX_PAYLOAD_SIZE];
-    char sn[SN_SIZE + 1];
-    char crc[CRC_SIZE + 1];
-} Frame_Package;
-
-int main(int argc, char *argv[]) {
-    FILE *in = fopen(infilename, "rb");
-    FILE *out = fopen(outfilename, "w");
-
-    while (feof(in)) {
-        Frame_Package frame;
-        memset(&frame, 0, sizeof(Frame_Package));
-        fread(&frame.frame_size, sizeof(int), 1, in);
-        fread(frame.destination_address, DESTINATION_ADDRESS_SIZE, 1, in);
-        fread(frame.source_address, SOURCE_ADDRESS_SIZE, 1, in);
-        fread(frame.ipv4, IPV4_SIZE, 1, in);
-        fread(frame.ip_structure, IP_STRUCTURE_SIZE, 1, in);
-        fread(frame.udp_structure, UDP_STRUCTURE_SIZE, 1, in);
-        fread(frame.afdxES_payload, frame.frame_size - DESTINATION_ADDRESS_SIZE -
-              SOURCE_ADDRESS_SIZE - IPV4_SIZE - IP_STRUCTURE_SIZE -
-              UDP_STRUCTURE_SIZE - SN_SIZE - CRC_SIZE, 1, in);
-        fread(frame.sn, SN_SIZE, 1, in);
-        fread(frame.crc, CRC_SIZE, 1, in);
-
-        fprintf(out, "####################### Frame size: %d\n", frame.frame_size);
-        fprintf(out, "Destination Address: %s\n", frame.destination_address);
-        fprintf(out, "Source Address: %s\n", frame.source_address);
-        fprintf(out, "IPv4: %s\n", frame.ipv4);
-        fprintf(out, "IP Structure: %s\n", frame.ip_structure);
-        fprintf(out, "UDP Structure: %s\n", frame.udp_structure);
-        fprintf(out, "AFDX Payload: %s\n", frame.afdxES_payload);
-        fprintf(out, "SN: %s\n", frame.sn);
-        fprintf(out, "CRC: %s\n\n\n", frame.crc);
-    }
-
-    return 0;
-}
-
diff --git a/simics-workspace/modules/sample-frame-module/save_frame_into_disk.c b/simics-workspace/modules/sample-frame-module/save_frame_into_disk.c
index fc75bae..50d0939 100644
--- a/simics-workspace/modules/sample-frame-module/save_frame_into_disk.c
+++ b/simics-workspace/modules/sample-frame-module/save_frame_into_disk.c
@@ -11,7 +11,7 @@ typedef enum {
 FILE *frame_image[2];

 const char *filename[] = {
-    "sframe_image.bin"
+    "sframe_image.bin",
     "rframe_image.bin"
 };

@@ -35,13 +35,14 @@ void save_frame_into_disk(void *frame, void *frame_size, int frame_type) {
     int file_size = get_file_size(frame_type);

     if ((file_size != -1) && (file_size >= max_file_size)) {
-        fseek(frame_image, 0, SEEK_SET);
+        fseek(frame_image[frame_type], 0, SEEK_SET);
     } else {
-        fseek(frame_image, 0, SEEK_END);
+        fseek(frame_image[frame_type], 0, SEEK_END);
     }

     fwrite(frame_size, sizeof(*(uint32*)frame_size), 1, frame_image[frame_type]);
     fwrite(frame, *(uint32*)frame_size, 1, frame_image[frame_type]);
+    fflush(frame_image[frame_type]);
 }

 void init_frame_image(void) {