udp packte anfordern
-
Hallo,
ich habe ein Spiel IL2 1946, wenn ich die Ini-Datei von dem Spiel
um[DeviceLink]
port=10000erweitere, soll es möglich sein anfragen an das Spiel zu senden und zurück
bekommt man Informationen wie, Höhe, Geschwindigkeit, Roll, Pitch, etc etc.
Das Spiel sendet die Informationen nicht ständig, ich muss sie anfordern.
Hab allerding nix gefunden, die ich spieziell sagen kann, gib mir bitte
Packet 40.Lässt sich sowas mit c# system.net(.socket) realisieren oder mit directplay?
Wenn ja, hat jemand ein paar Links zu dem Thema, irgendwie findet man nicht
soviel dazu.Danke schonmal
-
-
hab schon einiges probiert, will aber irgendwie nicht.
hab es mit udpclient probiert, entweder hängt sich das programm auf,
remotehost schliesst vorhandene Verbindung, oder ich sende etwas an mich
selbst, schicke ich ne 40 los ,bekomme ich eine 40 zurück.Mit socket.sendto und recieved from, bekomme ich immer remotehost
schliesst vorhandene verbindung. ob udpclient oder mit socket kommt
die exeption immer bei recieve, udpclient.connect, udpclient.send
(oder socket.sendto, scheint zu funktionieren)vorallem was is der remotehost? mein rechner oder mein router?
denke eher mein rechner oder?
-
remotehost = Der Rechner zu dem du dich verbindest. Kann unter Umständen also auch dein eigener sein.
Poste doch mal ein wenig Code, vllt. kann man dir dann helfen
Hast du Informationen welche Daten das Spiel erwartet und welche es liefert?
-
Hi,
ok hier ein paar Infos
-------------------------------------------------------------------------------
key 40 - altimeter
key 81 - power
Query packet - R/40/81\1.6e-1
Return the aircraft altitude, and set the power to 1.6e-1.
Reply (answer) packet - A/40\534.3
Returns the current altitude 534.3 meters MSL.The DeviceLink interface is activated if the [DeviceLink] section is found in the
conf.ini file. Within this section, "port" specifies the number of UDP port for
data transfer.
Using "host" parameter one can specify the address of the network interface in
use.
The "IPS" parameter restricts the allowed client IP addresses. If the "IPS"
parameter is not found in the section, any IP address is allowed to connect.Ex.:
[DeviceLink]
port=10000
IPS=10.1.1.3 10.1.1.8Port number is 10000, allowed clients are 10.1.1.3 and 10.1.1.8.
1. Parameters - common.
Version
2 get()
return: string containing DeviceLink version id.accessible get
4 get(parameter key)
return: parameter key and 1 or 0 - wheither this key has get method
allowed in the current context (I.e. allowed during the mission
but not while mission is loading).-----------------------------------------------------------------------------
So ich hab mit dem geredet, der so ein Programm schonmal in C++ geschrieben
hatte. Ich will dass, das Spiel und mein Programm zur Abfrage auf dem selben
PC laufen. Dafür wollt ich meine IP nehmen und die 127.0.0.1, mit 127.0.0.1
kann es wohl Probleme geben, er schrieb mir in einer e-mail folgendes:------------------------------------------------------------------------------
Scenario #1: 2 seperate boxes
Box #1: IP = 192.168.0.1 - This is the machine the game is running on.
Box #2: IP = 192.168.0.2 - This is the box your client C# program is running on.On Box #1, in the main IL2 1946 directory edit the conf.ini file and add the lines for DeviceLink to
Port=10000
IPS=192.168.0.1, 192.168.0.2 <--optional, you could leave it blank to accept connections from all clientsIn your client, running on Box #2, you would put your address as 192.168.0.2 and the endpoint as 192.168.0.1.
Scenario #2 - running the game and the client on the same Box.
Assume it is Box #1. Set your address and endpoint as 192.168.0.1. I avoid using 127.0.0.1 because it limits your client to ONLY the same box. Using the actual IP doesn't introduce any delay and makes your client single or multi box capable from the start.The problem is 127.0.0.1 is a "special" address and isn't handled the same way in different socket libraries.
-------------------------------------------------------------------------------Leider hab ich nicht viel Erfahrung mit system.net(.socket)
vielleicht hab ich auch irgendwo nen denk fehler mit den IP's
hab glaub schon sämtliche möglichkeiten durchnamespace IL2_interface { public partial class Form1 : Form { IPHostEntry xhostentry = Dns.GetHostEntry(Dns.GetHostName()); IPAddress address; IPEndPoint xendpoint2; IPEndPoint xendpoint; EndPoint xe; Socket s; byte[] byteadress = { 127, 0, 0, 1 }; public Form1() { InitializeComponent(); address = new IPAddress(byteadress); xendpoint = new IPEndPoint(xhostentry.AddressList[0], 10000); xendpoint2 = new IPEndPoint(address, 10000); s = new Socket(xendpoint.Address.AddressFamily, SocketType.Dgram, ProtocolType.Udp); xe = (xendpoint2); label2.Text = "localhost: " + xendpoint.ToString(); //192.168.2.2:10000 label5.Text = "socket: " + xendpoint.ToString(); //192.168.2.2:10000 label3.Text = "sendto:" + xendpoint2.ToString(); //127.0.0.1:10000 label4.Text = "recievefrom" + xendpoint2.ToString(); //127.0.0.1:10000 } private void get_btn_Click(object sender, EventArgs e) { byte[] msg = Encoding.ASCII.GetBytes("2"); s.SendTo(msg, xendpoint2); byte[] Rmsg = new byte[16]; try { s.ReceiveFrom(Rmsg, ref xe); } catch (SocketException Sex) // here i get an exception {
hatte es auch mal mit udpclient probiert, und 2 rechnern, irgendwas scheint
bei mir zu fehlen. wie gesagt hab nicht viel erfahrung damit.namespace IL2_Udp_client { public partial class Form1 : Form { byte[] IP = new byte[4]; byte[] IP2 = new byte[4]; UdpClient client; IPEndPoint xIpEndPoint; IPEndPoint xIpEndPoint2; IPAddress address; IPAddress address2; public Form1() { InitializeComponent(); IP[0] = 192; IP[1] = 168; IP[2] = 2; IP[3] = 2; IP2[0] = 192; IP2[1] = 168; IP2[2] = 2; IP2[3] = 3; address = new IPAddress(IP); address2 = new IPAddress(IP2); xIpEndPoint = new IPEndPoint(address, 10000); xIpEndPoint2 = new IPEndPoint(address2, 10000); } private void connect_btn_Click(object sender, EventArgs e) { try { client = new UdpClient("192.168.2.2",10000) ; //client.Connect(address2, 10000); } catch (SocketException socketex) { label1.Text = socketex.ToString(); } } private void GetVer_btn_Click(object sender, EventArgs e) { try { byte[] msg = Encoding.ASCII.GetBytes("2"); client.Send(msg, msg.Length); } catch (SocketException SocketEx2) { label2.Text = SocketEx2.ToString(); } try { byte[] Rmsg = client.Receive(ref xIpEndPoint2); string data = Encoding.ASCII.GetString(Rmsg); label4.Text = "Version:" + data; client.Close(); } catch (SocketException SocketEx3) { label3.Text = SocketEx3.ToString(); } } } }
-
msdn schrieb:
You must call the Socket.Bind(EndPoint) method if you intend to receive connectionless datagrams using the ReceiveFrom method.
...vor s.ReceiveFrom(Rmsg, ref xe).