summaryrefslogtreecommitdiff
path: root/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example')
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/BroadcastReceive.py25
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/BroadcastSend.py30
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/MulticastReceive.py31
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/MulticastSend.py30
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/TCPEchoClient.py28
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/TCPEchoServer.py30
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/UDPEchoClient.py28
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/UDPEchoServer.py27
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/__init__.py16
9 files changed, 245 insertions, 0 deletions
diff --git a/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/BroadcastReceive.py b/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/BroadcastReceive.py
new file mode 100644
index 0000000000..2e846ca19e
--- /dev/null
+++ b/tmk_core/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/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/BroadcastSend.py b/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/BroadcastSend.py
new file mode 100644
index 0000000000..0a5f8c3201
--- /dev/null
+++ b/tmk_core/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/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/MulticastReceive.py b/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/MulticastReceive.py
new file mode 100644
index 0000000000..9001f40b7d
--- /dev/null
+++ b/tmk_core/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/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/MulticastSend.py b/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/MulticastSend.py
new file mode 100644
index 0000000000..8efd4534ae
--- /dev/null
+++ b/tmk_core/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/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/TCPEchoClient.py b/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/TCPEchoClient.py
new file mode 100644
index 0000000000..dfa9bfdae7
--- /dev/null
+++ b/tmk_core/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/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/TCPEchoServer.py b/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/TCPEchoServer.py
new file mode 100644
index 0000000000..1324edbe64
--- /dev/null
+++ b/tmk_core/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/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/UDPEchoClient.py b/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/UDPEchoClient.py
new file mode 100644
index 0000000000..6a6cf8c902
--- /dev/null
+++ b/tmk_core/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/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/UDPEchoServer.py b/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/UDPEchoServer.py
new file mode 100644
index 0000000000..38503489ee
--- /dev/null
+++ b/tmk_core/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/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/__init__.py b/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/example/__init__.py
new file mode 100644
index 0000000000..10e7e1d1de
--- /dev/null
+++ b/tmk_core/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