python bind is error in matlab

5 views (last 30 days)
パンダ
パンダ on 16 Dec 2021
Commented: Kojiro Saito on 21 Dec 2021
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 Comment
Kojiro Saito
Kojiro Saito on 21 Dec 2021
私の環境では、上記のコードでエラーが再現しませんでした。
どこかで
self.sock.bind(self.SrcAddr)
# または
#self.sock.bind((self.ip, self.port))
のところが括弧1つの
self.sock.bind(self.ip, self.port)
になっているなどありませんでしょうか?

Sign in to comment.

Answers (0)

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!