Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
dart查询Steam主服务器_Dart_Server_Udp_Steam - Fatal编程技术网

dart查询Steam主服务器

dart查询Steam主服务器,dart,server,udp,steam,Dart,Server,Udp,Steam,我试图通过查询从steam主服务器获取服务器IP,然后再查询游戏服务器。 有很多不同编程语言的示例,但dart除外。 我的问题是:我甚至不明白为什么地址“hl2master.steampowered.com”是无效的互联网地址。在官方的valve Master Server查询(链接在帖子顶部)中也有这样的说法 这是我在尝试运行代码时遇到的错误: [错误:flatter/lib/ui/ui_dart_state.cc(148)]未处理的异常:无效参数:无效的internet地址hl2mast

我试图通过查询从steam主服务器获取服务器IP,然后再查询游戏服务器。

有很多不同编程语言的示例,但dart除外。

我的问题是:我甚至不明白为什么地址“hl2master.steampowered.com”是无效的互联网地址。在官方的valve Master Server查询(链接在帖子顶部)中也有这样的说法

这是我在尝试运行代码时遇到的错误: [错误:flatter/lib/ui/ui_dart_state.cc(148)]未处理的异常:无效参数:无效的internet地址hl2master.steampowered.com

import 'dart:io';
import 'dart:convert';

// Master server:
const GOLD_SRC = "hl1master.steampowered.com";
const GOLD_SRC_PORT = 27010;

const SOURCE = "hl2master.steampowered.com";
const SOURCE_PORT = 27011;

// Regions:
const US_EAST_COAST = 0x00;
const US_WEST_COAST = 0x01;
const SOUTH_AMERICA = 0x02;
const EUROPE        = 0x03;
const ASIA          = 0x04;
const AUSTRALIA     = 0x05;
const MIDDLE_EAST   = 0x06;
const AFRICA        = 0x07;
const ALL           = 0xFF;



class MasterServerQuery {
  connectSocket01() async {
    var message = "31 FF 30 2E 30 2E 30 2E";
    InternetAddress master = InternetAddress(SOURCE);
    var masterPort = SOURCE_PORT;
    RawDatagramSocket.bind(InternetAddress.anyIPv4, 4096).then((
        RawDatagramSocket socket) {
      print('UDP Echo ready to receive');
      print('${socket.address.address}:${socket.port}');
      socket.listen((RawSocketEvent e) {
        Datagram d = socket.receive();
        if (d == null) return;

        String message = "31 FF 30 2E 30 2E 30 2E";
        print(
            'Datagram from ${d.address.address}:${d.port}: ${message.trim()}');

        socket.send(message.codeUnits, master, masterPort);
      });
    });
  }
}

地址无效,因为它需要的是有效的ip地址而不是主机名,您可以提供ip地址或使用
InternetAddress.lookup

您的代码在传递消息的方式上也是错误的,您不应该传递代码单元,而是以如下方式传递字节:

  final byteData = ByteData(8);
  byteData.setUint8(0, 0x31);
  byteData.setUint8(1, 0xFF);
  byteData.setUint8(2, 0x30);
  byteData.setUint8(3, 0x2E);
  byteData.setUint8(4, 0x30);
  byteData.setUint8(5, 0x2E);
  byteData.setUint8(6, 0x30);
  byteData.setUint8(7, 0x2E);
  byteData.buffer.asUint8List() //Pass this.

这是如何处理字符串的?与A2S_信息一样,您应该将字符串编码为uft8,然后设置字节。但是,如果您计划使用查询协议(而不是主协议)或rcon,我已经实现了,