summaryrefslogtreecommitdiff
path: root/tool/mbed/mbed-sdk/workspace_tools/host_tests/example
diff options
context:
space:
mode:
authorJun Wako <wakojun@gmail.com>2015-04-24 16:26:14 +0900
committerJun Wako <wakojun@gmail.com>2015-04-24 16:26:14 +0900
commit1fe4406f374291ab2e86e95a97341fd9c475fcb8 (patch)
tree1be0e16b4b07b5a31ea97ec50a9eb13a288c3d27 /tool/mbed/mbed-sdk/workspace_tools/host_tests/example
parenta20ef7052c6e937d2f7672dd59456e55a5c08296 (diff)
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
b9e0ea0 Merge commit '7fa9d8bdea3773d1195b04d98fcf27cf48ddd81d' as 'tool/mbed/mbed-sdk' 7fa9d8b Squashed 'tool/mbed/mbed-sdk/' content from commit 7c21ce5 git-subtree-dir: tmk_core git-subtree-split: b9e0ea08cb940de20b3610ecdda18e9d8cd7c552
Diffstat (limited to 'tool/mbed/mbed-sdk/workspace_tools/host_tests/example')
-rw-r--r--tool/mbed/mbed-sdk/workspace_tools/host_tests/example/BroadcastReceive.py25
-rw-r--r--tool/mbed/mbed-sdk/workspace_tools/host_tests/example/BroadcastSend.py30
-rw-r--r--tool/mbed/mbed-sdk/workspace_tools/host_tests/example/MulticastReceive.py31
-rw-r--r--tool/mbed/mbed-sdk/workspace_tools/host_tests/example/MulticastSend.py30
-rw-r--r--tool/mbed/mbed-sdk/workspace_tools/host_tests/example/TCPEchoClient.py28
-rw-r--r--tool/mbed/mbed-sdk/workspace_tools/host_tests/example/TCPEchoServer.py30
-rw-r--r--tool/mbed/mbed-sdk/workspace_tools/host_tests/example/UDPEchoClient.py28
-rw-r--r--tool/mbed/mbed-sdk/workspace_tools/host_tests/example/UDPEchoServer.py27
-rw-r--r--tool/mbed/mbed-sdk/workspace_tools/host_tests/example/__init__.py16
9 files changed, 245 insertions, 0 deletions
diff --git a/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/BroadcastReceive.py b/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/BroadcastReceive.py
new file mode 100644
index 0000000000..2e846ca19e
--- /dev/null
+++ b/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/BroadcastReceive.py
@@ -0,0 +1,25 @@
+"""
+mbed SDK
+Copyright (c) 2011-2013 ARM Limited
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+"""
+import socket
+
+BROADCAST_PORT = 58083
+
+s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+s.bind(('0.0.0.0', BROADCAST_PORT))
+
+while True:
+ print s.recvfrom(256)
diff --git a/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/BroadcastSend.py b/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/BroadcastSend.py
new file mode 100644
index 0000000000..0a5f8c3201
--- /dev/null
+++ b/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/BroadcastSend.py
@@ -0,0 +1,30 @@
+"""
+mbed SDK
+Copyright (c) 2011-2013 ARM Limited
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+"""
+import socket
+from time import sleep, time
+
+BROADCAST_PORT = 58083
+
+s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+s.bind(('', 0))
+s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
+
+while True:
+ print "Broadcasting..."
+ data = 'Hello World: ' + repr(time()) + '\n'
+ s.sendto(data, ('<broadcast>', BROADCAST_PORT))
+ sleep(1)
diff --git a/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/MulticastReceive.py b/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/MulticastReceive.py
new file mode 100644
index 0000000000..9001f40b7d
--- /dev/null
+++ b/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/MulticastReceive.py
@@ -0,0 +1,31 @@
+"""
+mbed SDK
+Copyright (c) 2011-2013 ARM Limited
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+"""
+import socket
+import struct
+
+MCAST_GRP = '224.1.1.1'
+MCAST_PORT = 5007
+
+sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
+sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+sock.bind(('', MCAST_PORT))
+mreq = struct.pack("4sl", socket.inet_aton(MCAST_GRP), socket.INADDR_ANY)
+
+sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
+
+while True:
+ print sock.recv(10240)
diff --git a/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/MulticastSend.py b/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/MulticastSend.py
new file mode 100644
index 0000000000..8efd4534ae
--- /dev/null
+++ b/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/MulticastSend.py
@@ -0,0 +1,30 @@
+"""
+mbed SDK
+Copyright (c) 2011-2013 ARM Limited
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+"""
+import socket
+from time import sleep, time
+
+MCAST_GRP = '224.1.1.1'
+MCAST_PORT = 5007
+
+sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
+sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
+
+while True:
+ print "Multicast to group: %s\n" % MCAST_GRP
+ data = 'Hello World: ' + repr(time()) + '\n'
+ sock.sendto(data, (MCAST_GRP, MCAST_PORT))
+ sleep(1)
diff --git a/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/TCPEchoClient.py b/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/TCPEchoClient.py
new file mode 100644
index 0000000000..dfa9bfdae7
--- /dev/null
+++ b/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/TCPEchoClient.py
@@ -0,0 +1,28 @@
+"""
+mbed SDK
+Copyright (c) 2011-2013 ARM Limited
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+"""
+import socket
+
+ECHO_SERVER_ADDRESS = "10.2.202.45"
+ECHO_PORT = 7
+
+s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+s.connect((ECHO_SERVER_ADDRESS, ECHO_PORT))
+
+s.sendall('Hello, world')
+data = s.recv(1024)
+s.close()
+print 'Received', repr(data)
diff --git a/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/TCPEchoServer.py b/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/TCPEchoServer.py
new file mode 100644
index 0000000000..1324edbe64
--- /dev/null
+++ b/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/TCPEchoServer.py
@@ -0,0 +1,30 @@
+"""
+mbed SDK
+Copyright (c) 2011-2013 ARM Limited
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+"""
+import socket
+
+s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+s.bind(('', 7))
+s.listen(1)
+
+while True:
+ conn, addr = s.accept()
+ print 'Connected by', addr
+ while True:
+ data = conn.recv(1024)
+ if not data: break
+ conn.sendall(data)
+ conn.close()
diff --git a/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/UDPEchoClient.py b/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/UDPEchoClient.py
new file mode 100644
index 0000000000..6a6cf8c902
--- /dev/null
+++ b/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/UDPEchoClient.py
@@ -0,0 +1,28 @@
+"""
+mbed SDK
+Copyright (c) 2011-2013 ARM Limited
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+"""
+import socket
+
+ECHO_SERVER_ADDRESS = '10.2.202.45'
+ECHO_PORT = 7
+
+sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+
+sock.sendto("Hello World\n", (ECHO_SERVER_ADDRESS, ECHO_PORT))
+response = sock.recv(256)
+sock.close()
+
+print response
diff --git a/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/UDPEchoServer.py b/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/UDPEchoServer.py
new file mode 100644
index 0000000000..38503489ee
--- /dev/null
+++ b/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/UDPEchoServer.py
@@ -0,0 +1,27 @@
+"""
+mbed SDK
+Copyright (c) 2011-2013 ARM Limited
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+"""
+import socket
+
+ECHO_PORT = 7
+
+sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+sock.bind(('', ECHO_PORT))
+
+while True:
+ data, address = sock.recvfrom(256)
+ print "datagram from", address
+ sock.sendto(data, address)
diff --git a/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/__init__.py b/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/__init__.py
new file mode 100644
index 0000000000..10e7e1d1de
--- /dev/null
+++ b/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/__init__.py
@@ -0,0 +1,16 @@
+"""
+mbed SDK
+Copyright (c) 2011-2013 ARM Limited
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+""" \ No newline at end of file