I wrote a simple web server using MATLAB. Following this the code. The problem is when I comment out while (1) and end. The code has no problem, when I type http://localhost:85
the browser received the HTML page correctly. But when I add while loop, I cannot even debug the code, whenever I set a breakpoint, MATLAB crashes, why?
import java.net.* java.io.* java.os.*
sSocket = ServerSocket(85)开发者_如何学Python;
sSocketClose = onCleanup( @() sSocket.close() );
while (1)
cSocket = sSocket.accept();
iStream = DataInputStream (cSocket.getInputStream() );
oStream = DataOutputStream(cSocket.getOutputStream());
Message200Header = ['HTTP/1.1 200 OK', char([13,10]), ...
'Content-Type: text/html', char([13,10]), ...
'Connection: close', char([13,10]), char([13,10])];
oStream.write(uint8(Message200Header), 0 , length(Message200Header));
page = '<html><body><h1>Hello world</h1></body></html>';
oStream.write(uint8(page), 0, length(page));
iStream.close();
oStream.close();
cSocket.close();
end
sSocket.close();
I change while (1) to for k = 1:2
when I run the code, MATLAB still crashes.
when I comment out the while/for , end and manually run the loop several times, then its OK, why?
精彩评论