Author Topic: Trouble Sending TCP Packets via Cloudflare Workers  (Read 937 times)

0 Members and 1 Guest are viewing this topic.

Offline xd1936

  • Member
  • *
  • Posts: 22
    • About Me
Trouble Sending TCP Packets via Cloudflare Workers
« on: May 18, 2023, 08:56:42 AM »
Howdy, all.

Cloudflare has a wonderful serverless platform called Cloudflare Workers that allows you to write code without worrying about underlying hardware or software. Yesterday, they announced that Workers now have the ability to connect directly over TCP sockets. I want to use this feature to send an APRS packet to CWOP.

I have the following function in my code:

Code: [Select]
export async function sendPacket(packet, server, port) {

  console.log('Opening connection to ' + server + ':' + port);

  const socket = connect({ "hostname": server, "port": port });
  const writer = socket.writable.getWriter();
  const reader = socket.readable.getReader();
  const encoder = new TextEncoder();
 
  // Wait for server's initial message - http://www.wxqa.com/faq.html
  let initialMessage = await reader.read();
  console.log('Received from server: ', new TextDecoder().decode(initialMessage.value));

  // Send login line
  const id = packet.split('>')[0];
  const loginLine = 'user ' + id + ' pass -1 vers cwop.rest 0.1\r\n';
  console.log('Sending to server: ', loginLine);
  let encoded = encoder.encode(loginLine);
  await writer.write(encoded);

  // Wait for server's acknowledgement
  let { value, done } = await reader.read();
  console.log('Received from server: ', new TextDecoder().decode(value));

  // Send packet
  console.log('Sending to server: ', packet);
  encoded = encoder.encode(packet + '\r\n');
  await writer.write(encoded);

  writer.close();
  reader.releaseLock();
 
  let serverResponse = new TextDecoder().decode(value);
  console.log('Received from server: ', serverResponse);

  console.log('Closing connection to ' + server + ':' + port);
 
  return new Response(serverResponse, { "headers": { "Content-Type": "text/plain" } });
 
}

The log shows the following:

Code: [Select]
Opening connection to rotate.aprs.net:14580
worker.js:15 Received from server:  # aprsc 2.1.5-g8af3cdc
worker.js:20 Sending to server:  user K9ZOG pass -1 vers cwop.rest 0.1
worker.js:26 Received from server:  # logresp K9ZOG unverified, server NINTH
worker.js:29 Sending to server:  K9ZOG>APRS,TCPIP*:@181242z4246.58N/0866.22W_119/001g001t048r000p000h64b09968L162appsscriptforwarder
worker.js:37 Received from server:  # logresp K9ZOG unverified, server NINTH
worker.js:39 Closing connection to rotate.aprs.net:14580

This has been running every five minutes for over a day now, but my data is still not showing up on findu, aprs.fi, cwopviewer.com, etc. Any ideas what might be going wrong?

Offline xd1936

  • Member
  • *
  • Posts: 22
    • About Me
Re: Trouble Sending TCP Packets via Cloudflare Workers
« Reply #1 on: May 30, 2023, 04:09:34 PM »
Turns out, the errors were on the receiving server side. I was supposed to be sending to server x instead of server y. Disregard!

 

anything