tcpclient: slow connection

14 vues (au cours des 30 derniers jours)
Zohar
Zohar le 3 Nov 2021
Modifié(e) : Zohar le 4 Nov 2021
The following:
t = tcpclient('localhost', port);
takes about 2sec instead of being instantaneous.
I'm connecting to a python server (runs in a short script), which was tested with a python client.
An example server:
#!/usr/bin/env python3
import socket
HOST = '127.0.0.1'
PORT = 65432
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
with conn:
print('Connected by', addr)
while True:
data = conn.recv(1024)
if not data:
break
print( data )
An example client:
%echotcpip( "on", 65432 )
tic;
%t = tcpclient( '127.0.0.1', 65432 );
t = tcpclient( 'localhost', 65432 );
toc;
write(t, uint8('hi'));
clear t
%echotcpip("off")
Playing with it further:
  • There's no slowdown when connecting to echotcpip.
  • If I connect to '127.0.0.1', there's no slowdown. According to the doc, this address uses IPv4, while 'localhost' uses IPv6. Maybe it's something with my win10 (which is totally unreliable, and you can't know what they break each update).

Réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by