Use Network.Client to get the definition of a word from Dict.org

brathbone

Member
Licensed User
Just a simple example of using a socket to connect to Dict.org and grab a word definition.

I've been having fun playing with client protocols and thought I'd share this in case anyone was in need of such a thing.

:)
 

Attachments

  • Dictionary_client.zip
    8.1 KB · Views: 468

alfcen

Well-Known Member
Licensed User
Longtime User
Hi Brian,
Since I never persued the network.dll, your routine will be of great help.
In parallel, your chosen example is educative :)
Thanks a lot for sharing it.
Robert
 

brathbone

Member
Licensed User
Thanks to agraham for answering mamuen's question. I seem to have fallen asleep at the wheel :sign0013:

I'm glad this example is proving to be useful. Having access to a TCP socket is hugely powerful and allows you to do a lot of different things.

For a far more complex example, check out my TCP socket-based FTP example here:

http://www.b4x.com/forum/showthread.php?t=1734

All the best,
 

alfcen

Well-Known Member
Licensed User
Longtime User
Hi Brian,

Thanks to your post I checked the dict.org site exploring all
its query features. I felt that more information is provided
via HTTP access and wrote a little app that sends a query string,
parses the returned HTML file and displays the result.
I still have to work on formatting the result text.
Help File and Download CAB menus are still dummy functions.

BTW, how do you know whether a server allows TCP access
and the required parameters? A weather data server would be
nice for TCP access, wouldn't it.

Anyway, thanks a lot for the inspiration.

Cheers
Robert
 

Attachments

  • Jisho.zip
    172 KB · Views: 305

brathbone

Member
Licensed User
Hi Robert,

Nice app! The HTTP approach will be very useful when talking to most web based apps. The TCP socket approach is lower-level, but useful when HTTP access is not present. I started playing with network.dll to figure out how to create a Basic4PPC version of my remote technical support software for handhelds. It's basically on demand remote technical support for multiple platforms.

Regarding TCP access to various servers, the process ranges from reading RFCs and documentation to black art. Dict.org is such a great example because it is free and fairly well documented, although reading RFCs is not exactly fun. This approach is the best learning exprience, IMO.

If you don't really want to know all the ins and outs of the protocol, it is often better to look for open source projects in other languages and port the code.

Here are a couple examples of what I use TCP sockets for and, in short, how I figured them out:

FTP - Read the RFCs and looked at open-source FTP code.

Flash - I wrote a TCP server that communicated with a Flash/Actionscript web page using Flash's XMLSocket, which is a limited TCP socket in disguise. After connecting to the XMLSocket and having it write data to my client socket, I looked at each character as they came in (using ASC) and figured out that Flash's XML socket terminates every command with CHR(0). Most protocols that use terminator-based commands use CHR(13) & CHR(10), aka vbCRLF, as the terminator. Once I knew the terminator, which is used for sending and receiving, implementing my own custom protocol was no problem.

HTTP + Proxy server + progress - Using a TCP socket, we can build an HTTP socket from the ground up. This can be useful, as shown in the FTP example, to get low-level access to the protocol, and get the ability to provide progress during downloads. I haven't looked for a HTTP download with progress project in Basic4PPc yet, but if one doesn't exist, I'll probably port my HTTP code.

Lastly, if you need to figure out a protocol using more brute-force methods, then I recommend using telnet to connect to the host on the specified port and see what you get. For example, if you telnet to a FTP server on port 21, and follow the sequence in my example code, you can manually type in the protocol commands in telnet. It's pretty cool. Another way to do this is to use a packet sniffer to watch the TCP conversation between client and host.

None of this is easy, but it can be very worthwhile. I hope all my rambling is helpful. Let me know if I can be of assistance.

All the best,
 

alfcen

Well-Known Member
Licensed User
Longtime User
Hi Brian,

Thanks so much for all your time and for opening doors to other worlds :)

Cheers
Robert
 

brathbone

Member
Licensed User
Robert,

Regarding your interest in a weather server, have a look at:

http://developer.yahoo.com/weather/#examples

You can use your HTTP request method and get back an XML response. You can pass either latitude and longitude, Yahoo location code, or postal code.

For non-commercial use, this should work great.

I found another similar API:

http://meteostone.com/api/

I signed up for an API key and got one, but I just can't seem to get it to actually return me any weather data.

All the best,
 

alfcen

Well-Known Member
Licensed User
Longtime User
Hi Brian,
Thanks a lot for the URLs. XML is a welcome format.
Presently, I am parsing weather data from
http://i.wund.com/cgi-bin/findweather/getForecast?query=okinawa

Wunderground offers short update cycles and their accuracy ain't bad at all,
even for non-US locations :)

A CF type weather station with temperature, humidity and pressure
sensor would be nice for Pocket PCs... not talking about space weather ;)

Thanks for your kindness
Robert
 
Top