필터 지우기
필터 지우기

Tcpclient send [FIN, ACK]

조회 수: 11 (최근 30일)
Malin
Malin 2023년 2월 17일
댓글: Malin 2023년 3월 23일
Hi!
I'm trying to communicate with an external server from MATLAB using tcpclient.
To test the connection, the server can be quarried with a ping sending a message in the format '{ "Ping" : 1 }', the response is '{ "Pong" : 1 }'.
Using wireshark, a correct sequence for the ping procedure is:
i.e. the server expects a tcp packet with the FIN flag enabled indicating "end of message" .
Using python the behavior can be replicated using the socket library
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('localhost', 8333))
s.sendall('{ "Ping" : 1 }'.encode())
s.shutdown(1)
data = s.recv(15)
print ('Received', data.decode())
Using Matlab and tcpclient I'm not able to get this behavior with the FIN packets, indicating end of message.
I've tried
client = tcpclient("0.0.0.0",8333,'Timeout',1)
configureTerminator(client,"CR")
data='{ "Ping" : 1 }'
writeline(client,data)
response=readline(client)
fclose(client);
delete(client)
but the server only response after getting a [FIN] packet, which only occurs with "delete(client)", which means I cannot handle the response as I've just deleted the client.
My question is if there's a way to sending a [FIN] packet without deleting the object handling the communication using tcpclient and Matlab?
Kind regards
/Marcus

채택된 답변

Surya
Surya 2023년 3월 20일
Hi,
You can make use to Python MATLAB interface to resolve the issue.
Here is the sample code,
s = py.socket.socket(py.socket.AF_INET, py.socket.SOCK_STREAM)
s.connect({'localhost', int32(8333)});
req = py.str('{ "Ping" : 1 }').encode()
s.sendall(req);
s.shutdown(1);
data = s.recv(15)
For this to work, you need MATLAB compatible python installed in your system. here
  댓글 수: 1
Malin
Malin 2023년 3월 23일
Hi,
Thanks for the answer, didn't know about the Python MATLAB so will try your approach!
/Marcus

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by