DEV Community

Cover image for Connect to Tru peers using unix socket
Kirill Scherba
Kirill Scherba

Posted on • Edited on

Connect to Tru peers using unix socket

If you can't link the Tru package to your application than use this standalone unix socket server to communicate with any Tru peers.

The Unix socket Server created on golang and can run under Linux or Windows.

The Unix socket Cliens examples created on Go, C, C++ and build-in sample Visual Studio project.

See the part of C++ code to connect to the Unix socket Server:

int main(int argc, char *argv[]) {

  // Get unix socket path
  std::string socket_path = std::string("/tmp/trugw.sock");

  // Get tru peer address
  std::string tru_addr = ":7070";
  if (argc >= 2) {
    tru_addr = std::string(argv[1]);
  }

  std::cout << "Trugw C++ client, "
            << "sock path: " << socket_path << "tru peer: " << socket_path
            << std::endl;

  // Connect to teogw server
  std::cout << "trying to connect...\n";
  Trugw tgw(socket_path, tru_addr);
  if (!tgw.connected()) {
    std::cout << "can't connect\n";
    return 1;
  }
  std::cout << "connected \n";

  // Send messages
  for (int i = 0; i < 50000; i++) {
    std::string msg = "Hello " + std::to_string(i);
    std::cout << "send " << msg << std::endl;
    tgw.send(msg);

    uint8_t buf[1024];
    auto n = tgw.recv((const char *)buf, sizeof(buf), 0);
    std::string s((const char *)buf, n);
    std::cout << "receive " << s << std::endl;
  }

  return 0;
}
Enter fullscreen mode Exit fullscreen mode

See the code and more descriptions and example at: https://github.com/teonet-go/trugw

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

AWS GenAI Live!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️