Guest User

Untitled

a guest
Apr 25th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. exports.handler = async (event,context,callback) => {
  2. // console.log('Received event:', JSON.stringify(event, null, 2));
  3. var key=event.queryStringParameters.ref;
  4. // console.log('index.handler started with key : '+key);
  5. var RemoteServer='aaa.bbb.ccc.ddd';
  6. var net = require('net');
  7. var responce={
  8. "statusCode": 200,
  9. "headers": {
  10. "Content-Type": "*/*"
  11. }
  12. };
  13.  
  14. var socket = new net.Socket();
  15.  
  16. socket.setEncoding('utf8');
  17.  
  18. socket.on('close', () => {
  19. console.log('Close.');
  20. console.log(JSON.stringify(responce));
  21. callback(null, JSON.stringify(responce));
  22.  
  23. });
  24. socket.on('connect', () => {
  25. // console.log('Connect');
  26. var senddata='1,'+key;
  27. // console.log(('About to write :'+senddata));
  28. socket.write(senddata);
  29. console.log(('Wrote :'+senddata));
  30. });
  31. socket.on('data', (data) => {
  32. console.log('Data.');
  33. responce.body = data;
  34. console.log(JSON.stringify(responce));
  35. socket.end();
  36. });
  37. socket.on('end', () => {
  38. console.log('End.');
  39. console.log(JSON.stringify(responce));
  40. });
  41. socket.on('error', (error) => {
  42. console.log('Error' + error);
  43. socket.destroy;
  44. callback(error);
  45. });
  46. socket.on('timeout', () => {
  47. console.log('Timeout');
  48. socket.close;
  49. callback('Timeout');
  50. });
  51.  
  52. socket.connect(11010, RemoteServer, () => {
  53. // console.log('socket connect');
  54. });
  55.  
  56. callback(null,responce); // This is here to get this to do anything.
  57. };
  58.  
  59. START RequestId: 7e1876fe-4255-12de-56d6-c187bcfff9ee Version: $LATEST
  60. Wrote :1,R9H39X
  61. Data.
  62. {"statusCode":200,"headers":{"Content-Type":"*/*"},"body":"<?xml version="1.0" encoding="utf-8"?>rn<group>rn <data>rn <name>COLIN MANNING</name>rn <from>26/03/2018</from>rn <to>31/05/2018</to>rn <room>A31</room>rn <location>X,Y</location>rn </data>rn</group>rn"}
  63. End.
  64. {"statusCode":200,"headers":{"Content-Type":"*/*"},"body":"<?xml version="1.0" encoding="utf-8"?>rn<group>rn <data>rn <name>COLIN MANNING</name>rn <from>26/03/2018</from>rn <to>31/05/2018</to>rn <room>A31</room>rn <location>X,Y</location>rn </data>rn</group>rn"}
  65. Close.
  66. {"statusCode":200,"headers":{"Content-Type":"*/*"},"body":"<?xml version="1.0" encoding="utf-8"?>rn<group>rn <data>rn <name>COLIN MANNING</name>rn <from>26/03/2018</from>rn <to>31/05/2018</to>rn <room>A31</room>rn <location>X,Y</location>rn </data>rn</group>rn"}
  67. END RequestId: 7e1876fe-4255-12de-56d6-c187bcfff9ee
  68. REPORT RequestId: 7e1876fe-4255-12de-56d6-c187bcfff9ee Duration: 178.76 ms Billed Duration: 200 ms Memory Size: 1536 MB Max Memory Used: 33 MB
  69.  
  70. {"statusCode":200,"headers":{"Content-Type":"*/*"}}
  71.  
  72. START RequestId: c3dc7e69-87aa-1608-76d4-093a0e28711b Version: $LATEST
  73. END RequestId: c3dc7e69-87aa-1608-76d4-093a0e28711b
  74. REPORT RequestId: c3dc7e69-87aa-1608-76d4-093a0e28711b Duration: 3.43 ms Billed Duration: 100 ms Memory Size: 1536 MB Max Memory Used: 33 MB
  75.  
  76. null
Add Comment
Please, Sign In to add comment