summaryrefslogtreecommitdiffstats
path: root/robotframework-onap/ONAPLibrary/SocketKeywords.py
blob: 08a3fc72aa93c61ae2d040346d7729fa8a81a8f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import socket
from robot.api.deco import keyword


class SocketKeywords(object):
    """SocketKeywords are common resource for simple socket keywords."""

    def __init__(self):
        super(SocketKeywords, self).__init__()

    @keyword
    def send_binary_data(self, host, port, data):
        """ send raw bytes over tcp socket"""
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        # Connect to server and send data
        sock.connect((host, int(port)))
        sock.sendall(bytes(data))
        sock.close()