You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2004 The WebRTC Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include <iostream> // NOLINT
  11. #include <memory>
  12. #include "p2p/base/relay_server.h"
  13. #include "rtc_base/async_udp_socket.h"
  14. #include "rtc_base/socket_address.h"
  15. #include "rtc_base/socket_server.h"
  16. #include "rtc_base/thread.h"
  17. int main(int argc, char** argv) {
  18. if (argc != 3) {
  19. std::cerr << "usage: relayserver internal-address external-address"
  20. << std::endl;
  21. return 1;
  22. }
  23. rtc::SocketAddress int_addr;
  24. if (!int_addr.FromString(argv[1])) {
  25. std::cerr << "Unable to parse IP address: " << argv[1];
  26. return 1;
  27. }
  28. rtc::SocketAddress ext_addr;
  29. if (!ext_addr.FromString(argv[2])) {
  30. std::cerr << "Unable to parse IP address: " << argv[2];
  31. return 1;
  32. }
  33. rtc::Thread* pthMain = rtc::Thread::Current();
  34. std::unique_ptr<rtc::AsyncUDPSocket> int_socket(
  35. rtc::AsyncUDPSocket::Create(pthMain->socketserver(), int_addr));
  36. if (!int_socket) {
  37. std::cerr << "Failed to create a UDP socket bound at" << int_addr.ToString()
  38. << std::endl;
  39. return 1;
  40. }
  41. std::unique_ptr<rtc::AsyncUDPSocket> ext_socket(
  42. rtc::AsyncUDPSocket::Create(pthMain->socketserver(), ext_addr));
  43. if (!ext_socket) {
  44. std::cerr << "Failed to create a UDP socket bound at" << ext_addr.ToString()
  45. << std::endl;
  46. return 1;
  47. }
  48. cricket::RelayServer server(pthMain);
  49. server.AddInternalSocket(int_socket.get());
  50. server.AddExternalSocket(ext_socket.get());
  51. std::cout << "Listening internally at " << int_addr.ToString() << std::endl;
  52. std::cout << "Listening externally at " << ext_addr.ToString() << std::endl;
  53. pthMain->Run();
  54. return 0;
  55. }