From 6dbf38a923b9b902e2a75f0c9f157450816d7d95 Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期四, 23 七月 2020 18:07:49 +0800
Subject: [PATCH] update

---
 demo/dgram_mod_req_rep         |    0 
 demo/dgram_mod_req_rep.sh      |    5 +
 demo/stream_mod_req_rep.c      |   60 ++++++++++++++++++++
 demo/dgram_mod_survey          |    0 
 demo/stream_mod_pub_sub.c      |   57 +++++++++++++++++++
 test_socket/stream_mod_req_rep |    0 
 6 files changed, 122 insertions(+), 0 deletions(-)

diff --git a/demo/dgram_mod_req_rep b/demo/dgram_mod_req_rep
new file mode 100755
index 0000000..96eaae7
--- /dev/null
+++ b/demo/dgram_mod_req_rep
Binary files differ
diff --git a/demo/dgram_mod_req_rep.sh b/demo/dgram_mod_req_rep.sh
new file mode 100755
index 0000000..463db21
--- /dev/null
+++ b/demo/dgram_mod_req_rep.sh
@@ -0,0 +1,5 @@
+ipcrm -a
+
+./dgram_mod_req_rep server 8 & node0=$!
+./dgram_mod_req_rep client 8 node1
+kill $node0
\ No newline at end of file
diff --git a/demo/dgram_mod_survey b/demo/dgram_mod_survey
new file mode 100755
index 0000000..1202691
--- /dev/null
+++ b/demo/dgram_mod_survey
Binary files differ
diff --git a/demo/stream_mod_pub_sub.c b/demo/stream_mod_pub_sub.c
new file mode 100644
index 0000000..78aff69
--- /dev/null
+++ b/demo/stream_mod_pub_sub.c
@@ -0,0 +1,57 @@
+#include "mod_socket.h"
+#include "shm_mm.h"
+#include "usg_common.h"
+
+
+void server(int port) {
+	void *socket = mod_open_socket(PUB_SUB);
+	mod_socket_bind(socket, port);
+	mod_listen(socket);
+	int size;
+	void *recvbuf;
+	char sendbuf[512];
+	while(true) {
+		printf("璇疯緭鍏ュ彂甯冩秷鎭�:");
+		scanf("%s", sendbuf);
+		mod_send(socket, sendbuf, strlen(sendbuf)+1) ;
+		free(recvbuf);
+
+	}
+	mod_close_socket(socket);
+}
+
+void client(int port) {
+	void *socket = mod_open_socket(PUB_SUB);
+	mod_connect(socket, port);
+	int size;
+	void *recvbuf;
+ 
+	while(mod_recv(socket, &recvbuf, &size) == 0) {
+		printf("鏀跺埌璁㈤槄娑堟伅: %s\n", (char *)recvbuf);
+		free(recvbuf);
+
+	}
+	mod_close_socket(socket);
+}
+
+int main(int argc, char *argv[]) {
+  shm_init(512);
+  int port;
+  if (argc < 3) {
+  	 fprintf(stderr, "Usage: reqrep %s|%s <PORT> ...\n", "server", "client");
+  	 return 1;
+  }
+
+  port = atoi(argv[2]);
+
+  if (strcmp("server", argv[1]) == 0 ) {
+     server(port);
+  }
+
+  if (strcmp("client", argv[1]) == 0)
+     client(port);
+   
+ shm_destroy();
+ // fprintf(stderr, "Usage: reqrep %s|%s <URL> ...\n", "server", "client");
+  return 0;
+}
\ No newline at end of file
diff --git a/demo/stream_mod_req_rep.c b/demo/stream_mod_req_rep.c
new file mode 100644
index 0000000..5ae3133
--- /dev/null
+++ b/demo/stream_mod_req_rep.c
@@ -0,0 +1,60 @@
+#include "mod_socket.h"
+#include "shm_mm.h"
+#include "usg_common.h"
+
+void server(int port) {
+  void *socket = mod_open_socket(REQ_REP);
+  mod_socket_bind(socket, port);
+  mod_listen(socket);
+  int size;
+  void *recvbuf;
+  char sendbuf[512];
+  int rv;
+  while ( (rv = mod_recv(socket, &recvbuf, &size) ) == 0) {
+    sprintf(sendbuf, "SERVER RECEIVED: %s", recvbuf);
+    puts(sendbuf);
+    mod_send(socket, sendbuf, strlen(sendbuf) + 1);
+    free(recvbuf);
+  }
+  mod_close_socket(socket);
+}
+
+void client(int port) {
+  void *socket = mod_open_socket(REQ_REP);
+  mod_connect(socket, port);
+  int size;
+  void *recvbuf;
+  char sendbuf[512];
+  while (true) {
+    printf("request: ");
+    scanf("%s", sendbuf);
+    mod_send(socket, sendbuf, strlen(sendbuf) + 1);
+    mod_recv(socket, &recvbuf, &size);
+    printf("reply: %s\n", (char *)recvbuf);
+    free(recvbuf);
+  }
+  mod_close_socket(socket);
+}
+
+ 
+
+int main(int argc, char *argv[]) {
+  shm_init(512);
+  int port;
+  if (argc < 3) {
+    fprintf(stderr, "Usage: reqrep %s|%s <PORT> ...\n", "server", "client");
+    return 1;
+  }
+
+  port = atoi(argv[2]);
+
+  if (strcmp("server", argv[1]) == 0) {
+    server(port);
+  }
+
+  if (strcmp("client", argv[1]) == 0)
+    client(port);
+
+  
+  return 0;
+}
\ No newline at end of file
diff --git a/test_socket/stream_mod_req_rep b/test_socket/stream_mod_req_rep
new file mode 100755
index 0000000..8c5e1ff
--- /dev/null
+++ b/test_socket/stream_mod_req_rep
Binary files differ

--
Gitblit v1.8.0