Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed 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: 2,780
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:
Sub App_Start client.New1 client.Connect("xxx.xxx.xxx.xxx",23) msgbox("Client connected.") client.Close
End Sub

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: 2,780
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(0) As 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(4096) As 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
Knows the basics
 
Join Date: Apr 2008
Location: Duesseldorf, Germany
Posts: 71
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
    If client.DataAvailable Then        Dim buffer(4096) As 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: 2,780
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: 1,314
Awards Showcase
Forum Contributer 
Total Awards: 1
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: 2,780
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: 1,314
Awards Showcase
Forum Contributer 
Total Awards: 1
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
Knows the basics
 
Join Date: Apr 2008
Location: Duesseldorf, Germany
Posts: 71
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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
connectio tcpIP telnet protocol mircome Questions & Help Needed 2 06-22-2008 11:16 AM
Read NMEA from Server schimanski Questions & Help Needed 42 05-13-2008 08:42 AM
New server Erel Forum Discussion 12 11-06-2007 04:21 PM


All times are GMT. The time now is 08:41 PM.


Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0