Advertisement
Francoo

MATLAB TCP/IP Server/Client demo

Dec 24th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.87 KB | None | 0 0
  1. %Client side:
  2.  
  3. ip_address='189.101.243.232';
  4.  
  5. tcpipClient = tcpip(ip_address,44000,'NetworkRole','Client');
  6.  
  7. set(tcpipClient,'OutputBufferSize',10000);
  8. set(tcpipClient,'InputBufferSize',10000);
  9. set(tcpipClient,'Timeout',30);
  10. set(tcpipClient,'BytesAvailableFcn',@(~,~)disp(char(fread(tcpipClient,tcpipClient.BytesAvailable,'uint8'))'));
  11. enviar = @(x) fprintf(tcpipClient,'%s\n',x);
  12.  
  13. %Server side:
  14.  
  15. tcpipServer = tcpip('0.0.0.0',44000,'NetworkRole','Server');
  16.  
  17. set(tcpipServer,'OutputBufferSize',10000);
  18. set(tcpipServer,'InputBufferSize',10000);
  19. set(tcpipServer,'Timeout',30);
  20. set(tcpipServer,'BytesAvailableFcn',@(~,~)disp(char(fread(tcpipServer,tcpipServer.BytesAvailable,'uint8'))'));
  21. enviar = @(x) fprintf(tcpipServer,'%s\n',x);
  22.  
  23. %After setting up:
  24.  
  25. %Server:
  26.  
  27. fopen(tcpipServer);
  28. flushinput(tcpipClient);
  29.  
  30. %Client:
  31.  
  32. fopen(tcpipClient);
  33. flushinput(tcpipClient);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement