how can I reuse http connection when use webread to avoid server time wait?

4 Ansichten (letzte 30 Tage)
I use webread to get data from server. When I do it in parfor mode, it makes the remote server generate many timewait event. The reason is everytime, the webread open a port and request data and close it. The server cannot handle too many close requests at the same time. I want keep the port open to frequently read data from url
how can I reuse http connection when use webread to avoid server time wait?
aa=webread('http://172.16.2.1:5010/DFS/TNode/File?fileName=G0002-1/H02/2018/10/44/38/4a3cc8f1-b48f-40df-96b1-5d1e452fd63c',options);
for example, in python, I can do:
con = http.client.HTTPConnection("172.16.2.1", 5010)
while True:
con.request("GET", "/DFS/TNode/File?fileName=G0002-1/H02/2018/10/44/38/4a3cc8f1-b48f-40df-96b1-5d1e452fd63c", headers={"Connection":" keep-alive"})
result = con.getresponse()
result.read()
print(result.reason, result.getheaders())
and there is no time wait event
  2 Kommentare
Guofeng
Guofeng am 21 Sep. 2019
Have you deal with your problem?I have the same problem but do not konw how to speed the function time.
laroq
laroq am 4 Mai 2020
Same problem as you. Webread and urlread2 don't support connection reuse. Need a third party tool to feed the data to Matlab.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Mohammad Sami
Mohammad Sami am 4 Mai 2020
You will need to rely on java to accomplish this. A simple script to open a network connection and read from it is as follows.
url = java.net.URL(url);
HttpURLConnection = url.openConnection();
%connect_time_out = 60;
%HttpURLConnection.setConnectTimeout(connect_time_out);
httpcode = HttpURLConnection.getResponseCode;
ins = HttpURLConnection.getInputStream();
% copy the input stream into an output. you can directly read the input stream as well
output = java.io.ByteArrayOutputStream();
org.apache.commons.io.IOUtils.copy(ins,output);
output.flush();
string_output = char(output.toString);
output.close();
ins.close();

Weitere Antworten (0)

Kategorien

Mehr zu Call Web Services from MATLAB Using HTTP finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by