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

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

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Comunicating with a Telnet Server

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-06-2007, 09:10 AM
Newbie
 
Join Date: Nov 2007
Posts: 3
Question Comunicating with a Telnet Server

My question is, can I comunicate with a telnet server? I have a PPC application and i need to write and read string of text with a telnet server...
I'm trying to use Network.dll and BinaryStream.dll, but I don't have enough info and I don't know how to deal with these classes...
Any suggestion or example will be very appreciate!
Thanks!
Reply With Quote
  #2 (permalink)  
Old 11-06-2007, 10:12 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,726
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Do you know the server's IP?
Create a Client object and connect to this IP (use port 23):
Don't forget to add a reference to the Network library and add a Client object named client.
Code:
<div align="left"><font face="Courier New"><font color="#0000ff">Sub </font></font><font face="Courier New"><font color="#010101">App_Start</font></font>
<font face=
"Courier New"><font color="#010101">      client.New1</font></font>
<font face=
"Courier New"><font color="#010101">      client.Connect("xxx.xxx.xxx.xxx",23) </font></font>
<font face=
"Courier New"><font color="#0000ff">msgbox</font></font><font face="Courier New"><font color="#010101">("Client connected.")</font></font>
<font face=
"Courier New"><font color="#010101">      client.Close</font></font></div><font face="Courier New"><font color="#0000ff">End Sub
</font></font>

Reply With Quote
  #3 (permalink)  
Old 11-06-2007, 10:38 AM
Newbie
 
Join Date: Nov 2007
Posts: 3
Default

Ok, that's what i did... and it connects properly...
My biggest problem was the dialogue with the tother computer after connecting..
That's what i did:
Code:
Sub Connect(IP)
    
'ErrorLabel(errConnect)
    WaitCursor(true)
    TextBox2.Text = 
"Connecting to " & IP
    
Dim client
    client.New1
    client.Connect(IP,
23)
    stream.New1(client.GetStream,
true)
    TextBox2.Text = 
"Connection established."
    
Return
End Sub
I'm trying to read something from the server...I need to write sentences and read replies... Thanks for the quick answer!
Reply With Quote
  #4 (permalink)  
Old 11-06-2007, 10:52 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,726
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

You should remove the Dim client line.
Did you add a BinaryFile object named stream?
See this example:
You should add a Bitwise object named bit.
Code:
Sub Globals
    
Dim buffer(0As byte
End Sub

Sub App_Start
    
bit.New1
    AddTimer(
"Timer1")
    Timer1.Interval = 
500
End Sub

Sub Connect(IP)
    
'ErrorLabel(errConnect)
    WaitCursor(true)
    TextBox2.Text = 
"Connecting to " & IP
    client.New1
    client.Connect(IP,
23)
    stream.New1(client.GetStream,
true)
    TextBox2.Text = 
"Connection established."
    timer1.Enabled = 
true
    WaitCursor(
false)
End Sub

Sub Timer1_Tick
    
If client.DataAvailable Then
        
Dim buffer(4096As byte
        count = stream.ReadBytes(buffer(),
4096)
        TextBox2.Text = 
bit.BytesToString(buffer(),0,count)
    
End If
End Sub
Reply With Quote
  #5 (permalink)  
Old 05-01-2008, 02:28 AM
Senior Member
 
Join Date: Apr 2008
Location: Duesseldorf, Germany
Posts: 154
Default

Hello Erel,

i don't wanna highjack this thread, but i've got a question regardings this.

That piece never works for me:

Code:
Sub Timer1_Tick
   <font color=
"Red"If client.DataAvailable Then</font>        Dim buffer(4096As byte
        count = stream.ReadBytes(buffer(),
4096)
        TextBox2.Text = 
bit.BytesToString(buffer(),0,count)
    
End If
End Sub
The line

If client.DataAvailable Then
..
end if

gets never triggered and therefore i never catch the server's response.If i remove this check, i can read the server's response but run risk to get stuck because there's maybe no answer from the server pending anymore .


cheers

TWELVE
Reply With Quote
  #6 (permalink)  
Old 05-01-2008, 05:26 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,726
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

It's strange. DataAvailable should return the correct value.
See the ChitChat example which uses it.
Reply With Quote
  #7 (permalink)  
Old 05-01-2008, 09:56 AM
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

I can confirm that DataAvailable should work. I've used it in two apps so far, on the device and desktop. If the Dim Buffer... line really is there maybe it's upsetting things even if it does get through the compiler. Dim should only go in Globals.
Reply With Quote
  #8 (permalink)  
Old 05-01-2008, 10:26 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,726
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Small correction, it is fine (and many times necessary) to use the Dim keyword to redimension an array which was declared in Sub Globals.
Reply With Quote
  #9 (permalink)  
Old 05-01-2008, 10:38 AM
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

Sorry. You are right Erel, as usual. I had overlooked that possibility
Reply With Quote
  #10 (permalink)  
Old 05-01-2008, 02:37 PM
Senior Member
 
Join Date: Apr 2008
Location: Duesseldorf, Germany
Posts: 154
Default

Quote:
It's strange. DataAvailable should return the correct value.
I'll have a look at it again...

Cheers

TWELVE
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
Read NMEA from Server schimanski Questions (Windows Mobile) 64 01-11-2009 05:00 PM
One server adn more clients Byak@ Questions (Windows Mobile) 2 08-12-2008 10:59 AM
connectio tcpIP telnet protocol mircome Questions (Windows Mobile) 2 06-22-2008 11:16 AM
New server Erel Forum Discussion 12 11-06-2007 04:21 PM


All times are GMT. The time now is 05:43 AM.


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