udp客户端服务器程序与ibm bluemix容器的通信

时间:2016-01-13 04:17:03

标签: sockets docker udp containers ibm-cloud

我是bluemix容器的新手。我创建了一个bluemix容器并公开了端口5005以进行udp客户端服务器通信。该端口无法从主机接收来自我的程序的消息。

下面是我创建的Docker文件。

 FROM registry.ng.bluemix.net/ibmliberty:latest
 COPY pythonServer.py /home/
 EXPOSE 9080 5005/udp
 # Run Liberty via the supervisor
 CMD ["/root/bin/run_supervisor"]

我的python Udp服务器程序:

import SocketServer

class MyUDPHandler(SocketServer.BaseRequestHandler):
    """
    This class works similar to the TCP handler class, except that
    self.request consists of a pair of data and client socket, and since
    there is no connection the client address must be given explicitly
    when sending data back via sendto().
    """

    def handle(self):
        data = self.request[0].strip()
        socket = self.request[1]
        print "{} wrote:".format(self.client_address[0])
        print data
        socket.sendto(data.upper(), self.client_address)

if __name__ == "__main__":
    HOST, PORT = "0.0.0.0", 5005
    server = SocketServer.UDPServer((HOST, PORT), MyUDPHandler)

    server.serve_forever()

我的python udp客户端程序

import socket
import sys

HOST, PORT = "134.168.20.209", 5005
data = " ".join(sys.argv[1:])

# SOCK_DGRAM is the socket type to use for UDP sockets
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# As you can see, there is no connect() call; UDP has no connections.
# Instead, data is directly sent to the recipient via sendto().

while 1:
    data = raw_input("Enter something: ")
    print "you entered ", data
    sock.sendto(data , (HOST, PORT))
    received = sock.recv(1024)
    print "Sent:     {}".format(data)
    print "Received: {}".format(received)

我也暴露了端口5005,但它仍然无法与客户端程序通信。关于为什么端口没有暴露在bluemix容器中的任何问题?

1 个答案:

答案 0 :(得分:0)

出于安全原因,打开的端口数量有限,可以从外部访问。 UDP / TCP端口5005当前未包含在此集中。实际上现在没有暴露UDP端口。

我建议您与Bluemix支持团队一起打开支持请求,并请求打开此端口。

ibm.biz/bluemixsupport