Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Code Samples & Tips
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Code Samples & Tips Share your recent discoveries and ideas with other users.

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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-10-2008, 08:30 AM
brathbone's Avatar
Junior Member
 
Join Date: Feb 2008
Location: Rutherfordton, North Carolina
Posts: 25
Send a message via MSN to brathbone
Default Use Network.Client to get the definition of a word from Dict.org

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.

Attached Files
File Type: zip Dictionary_client.zip (8.1 KB, 164 views)
__________________
Brian Rathbone

Author of The Dawning of Power fantasy trilogy. Get the eBook for only $7.99

Device: Treo 750, WM6, 300mhz,128MB RAM, 2GB miniSD, 240x240 display
Reply With Quote
  #2 (permalink)  
Old 03-03-2008, 11:52 AM
Knows the basics
 
Join Date: Mar 2008
Location: germany, Heidelberg
Posts: 90
Default

Nice program,

did your program use a TCP or UDP Port for the socket?
Reply With Quote
  #3 (permalink)  
Old 03-03-2008, 12:12 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

The Network library uses TCP.
Reply With Quote
  #4 (permalink)  
Old 03-04-2008, 12:16 AM
alfcen's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Okinawa, Ryukyu Islands
Posts: 810
Send a message via Skype™ to alfcen
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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
Reply With Quote
  #5 (permalink)  
Old 03-04-2008, 07:57 PM
brathbone's Avatar
Junior Member
 
Join Date: Feb 2008
Location: Rutherfordton, North Carolina
Posts: 25
Send a message via MSN to brathbone
Default

Thanks to agraham for answering mamuen's question. I seem to have fallen asleep at the wheel

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.basic4ppc.com/forum/open-source-projects/1734-low-level-ftp-upload-progress.html

All the best,
__________________
Brian Rathbone

Author of The Dawning of Power fantasy trilogy. Get the eBook for only $7.99

Device: Treo 750, WM6, 300mhz,128MB RAM, 2GB miniSD, 240x240 display
Reply With Quote
  #6 (permalink)  
Old 03-05-2008, 08:04 AM
alfcen's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Okinawa, Ryukyu Islands
Posts: 810
Send a message via Skype™ to alfcen
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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
Attached Files
File Type: zip Jisho.zip (172.0 KB, 80 views)
Reply With Quote
  #7 (permalink)  
Old 03-06-2008, 07:45 AM
brathbone's Avatar
Junior Member
 
Join Date: Feb 2008
Location: Rutherfordton, North Carolina
Posts: 25
Send a message via MSN to brathbone
Default

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,
__________________
Brian Rathbone

Author of The Dawning of Power fantasy trilogy. Get the eBook for only $7.99

Device: Treo 750, WM6, 300mhz,128MB RAM, 2GB miniSD, 240x240 display
Reply With Quote
  #8 (permalink)  
Old 03-07-2008, 11:22 AM
alfcen's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Okinawa, Ryukyu Islands
Posts: 810
Send a message via Skype™ to alfcen
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Hi Brian,

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

Cheers
Robert
Reply With Quote
  #9 (permalink)  
Old 03-09-2008, 12:40 AM
brathbone's Avatar
Junior Member
 
Join Date: Feb 2008
Location: Rutherfordton, North Carolina
Posts: 25
Send a message via MSN to brathbone
Default

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,
__________________
Brian Rathbone

Author of The Dawning of Power fantasy trilogy. Get the eBook for only $7.99

Device: Treo 750, WM6, 300mhz,128MB RAM, 2GB miniSD, 240x240 display
Reply With Quote
  #10 (permalink)  
Old 03-09-2008, 03:34 AM
alfcen's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Okinawa, Ryukyu Islands
Posts: 810
Send a message via Skype™ to alfcen
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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/findweathe...?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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
MPD client for Windows Mobil mamuen Open Source Projects 3 08-11-2009 04:23 PM
Word wrap problem agraham Beta Versions 1 08-27-2008 10:02 AM
Client for MPD mamuen German Forum 17 03-19-2008 10:15 PM
How to achieve text edtion like in word? Cableguy Questions (Windows Mobile) 3 07-03-2007 03:52 PM
FTP Client PatrikL Share Your Creations 2 05-05-2007 06:54 AM


All times are GMT. The time now is 09:42 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0