Weather Related Organizations > CWOP Forum

Trouble Sending TCP Packets via Cloudflare Workers


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: ---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 -
  let initialMessage = await;
  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 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;
  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);

  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" } });
--- End code ---

The log shows the following:

--- Code: ---Opening connection to
worker.js:15 Received from server:  # aprsc 2.1.5-g8af3cdc
worker.js:20 Sending to server:  user K9ZOG pass -1 vers 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
--- End code ---

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

Turns out, the errors were on the receiving server side. I was supposed to be sending to server x instead of server y. Disregard!


[0] Message Index

Go to full version