python bind is error in matlab

3 次查看(过去 30 天)
パンダ
パンダ 2021-12-16
评论: Kojiro Saito 2021-12-21
python error: TypeError: bind() takes exactly one argument (2 given)
python code is here.
import socket
import time
import re
import cv2
from time import sleep
import struct
import numpy as np
import matlab
import json
class matserver:
ip='127.0.0.1'
port=12345
def __init__(self,ip,port):
self.ip = ip # 受信元IP
self.port = port # 受信元ポート番号
self.SrcAddr = (self.ip, self.port) # アドレスをtupleに格納
self.BUFSIZE = 1024 # バッファサイズ指定
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # ソケット作成
self.sock.bind(self.SrcAddr) # 受信元アドレスでバインド
def start_listening(self,callback=None):
try :
# ③Clientからのmessageの受付開始
#print('Waiting message')
message, cli_addr = self.sock.recvfrom(self.BUFSIZE)
message = message.decode(encoding='utf-8')
#print(f'Received message is [{message}]')
d = re.findall(r"[-+]?\d*\.\d+|\d+", message)
a = np.frombuffer(d, dtype=np.uint8, offset=8)
return a
#print(d)
# Clientが受信待ちになるまで待つため
#time.sleep(1)
# ④Clientへ受信完了messageを送信
#print('Send response to Client')
#sock.sendto('Success to receive message'.encode(encoding='utf-8'), cli_addr)
except KeyboardInterrupt:
self.sock.close()
return False # クラス呼び出し # 関数実行
I run matserver in matlab. error. why?
  1 个评论
Kojiro Saito
Kojiro Saito 2021-12-21
私の環境では、上記のコードでエラーが再現しませんでした。
どこかで
self.sock.bind(self.SrcAddr)
# または
#self.sock.bind((self.ip, self.port))
のところが括弧1つの
self.sock.bind(self.ip, self.port)
になっているなどありませんでしょうか?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB の Python ライブラリ 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!