Page 1 of 4

creating a socket to connect to existing servers

Posted: Sat Nov 06, 2010 3:02 pm
by maverickalex
Hi all, apologies in advance.

I am trying to make an application which would enable on the client side to connect to existing servers to extract data via xml.

The xml data is along the lines of.

Code: Select all

<?xml version="1.0"?>
<PropertyList>
 <generic>

  <output>
   <binary_mode>false</binary_mode>
   <var_separator> </var_separator>
   <line_separator>\n</line_separator>
   <preamble>register FlightGear</preamble>

   <chunk>
    <type>string</type>
    <format>put</format>
   </chunk>

   <chunk>
    <name>lat</name>
    <type>float</type>
    <node>/position/latitude-deg</node>
    <format>lat %f</format>
   </chunk>

   <chunk>
    <name>lon</name>
    <type>float</type>
    <node>/position/longitude-deg</node>
    <format>lon %f</format>
   </chunk>

   <chunk>
    <name>alt</name>
    <type>int</type>
    <node>/position/altitude-ft</node>
    <format>alt %d</format>
   </chunk>

   <chunk>
    <name>ground speed</name>
    <type>int</type>
    <node>/velocities/groundspeed-kt</node>
    <format>gnd %d</format>
   </chunk>

   <chunk>
    <name>heading</name>
    <type>int</type>
    <node>/orientation/heading-deg</node>
    <format>hdg %d</format>
    <factor>10</factor>
   </chunk>

   <chunk>
    <name>UTC hour</name>
    <type>int</type>
    <node>/sim/time/utc/hour</node>
    <format>hrs %d</format>
   </chunk>

   <chunk>
    <name>UTC min</name>
    <type>int</type>
    <node>/sim/time/utc/minute</node>
    <format>min %d</format>
   </chunk>
 
  </output>

 </generic>
</PropertyList>
The xml data is sent to existing servers (10 of them) by an existing application. where i can create new input/output commands in this way

Image

The ultimate aim is to have the application read the data and keep updating it every minute or so to update a live map.


are there any tutorials that i can follow that would help in my quest?

Thanks

Alex

Re: creating a socket to connect to existing servers

Posted: Sat Nov 06, 2010 5:53 pm
by Mark
Hi Alex,

First, you need to get the documentation of those servers. You need to know the exact protocol.

A protocol contains port information, commands to tell the server that your client software is genuine, more commands to communicate with the server and the complete specifications of the (xml) data.

As long as you don't have that, don't try it.

Best regards

Re: creating a socket to connect to existing servers

Posted: Sat Nov 06, 2010 6:19 pm
by maverickalex
MArk thanks for that, the whole project is open source so all the information is available to me, that wont be the problem.

details can be found here http://fgms.sourceforge.net/protocol.php

and http://fgms.sourceforge.net/protocol/index.html

Re: creating a socket to connect to existing servers

Posted: Sat Nov 06, 2010 6:25 pm
by Mark
Hi Alex,

In that case, you should post the link to the open-source project. If everybody can have a look at all the information, then it will become much easier to help you.

Also, you need to show your first attempts to implement the protocol and tell at which point you get stuck.

Except for some examples of socket communication, I don't know of any tutorials that might help you. I think there are some useful examples on RevOnline and probably on a few more rev-related internet sites. Start with a search for info about sockets in this forum.

Best regards,

Mark

Re: creating a socket to connect to existing servers

Posted: Sun Nov 07, 2010 10:58 am
by maverickalex
ok i am very early into the project. i have started by creating the socket connection using.

Code: Select all

on mouseUp
   open socket to "mpserver02.flightgear.org : 1974|ava-acars" with message "connecting to the server"
end mouseUp 
where mpserver is obviously the server to connect to
1974 is the port
ava-acars is the xml file for collecting the information.

i have created a substack with the fields i want the xml data to populate.

for example latfld to be populated by retrieving this info from the ava-acars.xml
<chunk>
<

Code: Select all

name>lat</name>
    <type>float</type>
    <node>/position/latitude-deg</node>
    <format>lat %f</format>
   </chunk
am i on the right track.

I don't necessarily need to input anything via the socket just yet,and the mainstack can just run quietly in the background although i will be wanting to populate a mysql database so my website can collect the data.

Re: creating a socket to connect to existing servers

Posted: Sun Nov 07, 2010 11:11 am
by Mark
Alex,

Please read the information about the "open socket" command in the dictionary and follow the advice in my previous post. I'm sure it will help you.

Kind regards,

Mark

Re: creating a socket to connect to existing servers

Posted: Sun Nov 07, 2010 12:15 pm
by maverickalex
Thanks Mark.

The open source project is http://www.flightgear.org a couple of years ago i created (with masses of help from the forum here) a simple GUI interface for windoze users which helped to write command line arguements easily with a point and click interface.

on this occassion what i am trying to do is create an application which will collect simple information such as callsign, lat, lon, altitude, heading, speed etc.

The user connects via flightgear on to public servers (as mentioned previously) to enable them to have online multiplayer.

I can enable Flightgear to output to any port number via --generic or --telnet connections to the socket.

there are a few wiki article on creating protocol for flightgear.
http://wiki.flightgear.org/index.php/Ho ... c_protocol
http://wiki.flightgear.org/index.php/Mu ... r_protocol

I read the open sockets info in the rev dictionary which is where i got the initial

Code: Select all

open socket to "mpserver02.flightgear.org : 1974|ava-acars" with message "connecting to the server
My wish is to have something like this.
Image

cheers
Alex

Re: creating a socket to connect to existing servers

Posted: Sun Nov 07, 2010 2:15 pm
by Mark
Hi Alex,

It is clear that you read the documentation about "open socket" but you haven't quite understood it yet. You added spaces and invented some kind of "message" ignoring the examples in the dictionary. Do you understand what the message does and why your message is wrong? Do you know what handler names in Revolution usually look like? It is really important that you grasp the basics of programming with Revolution (LiveCode) before you start a complex project like this.

According to the protocol, you need to communicate over UDP. The RunRev dictionary tells you how to do this.

Where did you get the information that data sent to the server should be in XML format? I can't find any information about the actual data format.

The website about the multiplayer protocol tells you exactly how to communicate to the server. Probably, "zero terminated string" means that all headers and the data are delimited by NULLs. You probably want to ask more about the protocol in the FG forums.

Tip: before you continue working on this, make a simple chat app that works over your local network to make sure that you understand sockets. The advantage of making your own chat server and client is that you can make your own protocol.

Kind regards,

Mark

Re: creating a socket to connect to existing servers

Posted: Sun Nov 07, 2010 10:55 pm
by maverickalex
the IO info is here

http://pastebin.com/K5UQgEP0

and the protocol info
http://pastebin.com/64wFj83R

Flightgear uses xml data to run most of the properties hence why we use xml to collect the data.

cheeers

Alex

Re: creating a socket to connect to existing servers

Posted: Mon Nov 08, 2010 12:01 am
by Mark
Hi Alex,

Yes, you already gave that info (it is the same as in the wiki).

I think it is time to first make sure you understand the basics and then make your first attempt to comunicate with FG.

Best regards,

Mark

Re: creating a socket to connect to existing servers

Posted: Mon Nov 08, 2010 1:07 pm
by maverickalex
ok using this code i think i have connected to port 5505 via localhost.

Code: Select all

on mouseUp
   open socket to"127.0.0.1:5505|ava-acars"
      read from socket sSocket until return
      put it into field "Event Log"
      close socket pSocket

   
  put empty into field "Event Log"
--  put "started" into field "My Status"
  reStart
end mouseUp
you can see in the image i enabled FG to accept socket connection on that port.

i used a chat example for a template and got a succesful connection message.

Image

Re: creating a socket to connect to existing servers

Posted: Mon Nov 08, 2010 1:19 pm
by Mark
maverickalex,

That looks good for a start. I would strongly recommend using message, though:

read from socket x with message "xyz"

This is really important when there is more traffic and the server might lag. Using messages will also allow you to keep the session alive, which is more efficient. You would use the close socket command only once to finish the session.

Kind regards,

Mark

Re: creating a socket to connect to existing servers

Posted: Mon Nov 08, 2010 2:05 pm
by maverickalex
that would be better.

when you suggest message "xyz" is that the message i want to send the server?

Re: creating a socket to connect to existing servers

Posted: Mon Nov 08, 2010 2:12 pm
by Mark
maverickalex ,

No, it is a message sent by Revolution to the object invoking the read from socket command. Revolution sends the message to allow you to run a script when data is received. You should be able to see this in the example stacks and the dictionary.

Best regards,

Mark

Re: creating a socket to connect to existing servers

Posted: Mon Nov 08, 2010 6:26 pm
by maverickalex
I'm glad this is the "complete beginners" forum.

how can i see info from the server?

I'm looking at as many sample stacks from online but without knowing exactly what to look for its a bit hit and miss.

to see the info im after you can look at the FG multimap which is a google map displaying the online users. if you click on one you see it displays certain parameters, its this along with some others i'm trying to capture.

http://mpmap02.flightgear.org/

my understanding is that my xml (protocol) file should be sent to the server and the server replies by sending the packet back containing the requested info?

Is this correct?

Please bear with me, once i get the hang of things, i''ll be ok.

i'm reading from this runrev tutorial assuming im more interested in the client side?
http://lessons.runrev.com/spaces/lesson ... ng-sockets