Problem with my VB.NET telnet client 
Author Message
 Problem with my VB.NET telnet client

(((To REPLY to my message, please remove the xyz from my email name:

I simplified my VB.NET telnet client code for troubleshooting and I use MUD
servers for testing it. You can compile and run this code to see the problem
(NOTE: To run it, you need a form1 with a richtextbox1, a textbox1, and two
buttons.).

It has the following problem:

The client connects to all servers and receives their welcome messages just
fine. But on some servers, after I get the welcome message and try to
respond with login text or whatever is requested, the server just sits there
like it never got my message. In the code comments below, I list two MUD
server addresses, one that works correctly and one that fails. I am really
stuck, any ideas would be greatly appreciated. Thanks!

Imports System.Net
Imports System.Net.Sockets

Public Class Form1
    Inherits System.Windows.Forms.Form

    Dim sock1 As New Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp)

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
        'This is the connect button
        Connect()
        Button2.Enabled = False
        Receive()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        'This is the send button
        Send()
        TextBox1.Text = ""
        Receive()
    End Sub

    Private Function Connect()
        'BAD connection example = 206.245.158.190 5000
        'GOOD connection example = 63.205.237.177 1912
        Dim myIP As IPAddress = IPAddress.Parse("63.205.237.177")
        'Parse the port number from the end of the string in the combobox
        Dim EPhost As New IPEndPoint(myIP, 1912)
        'Catch errors trying to connect to hosts that may not be there
        Try
            sock1.Connect(EPhost)
        Catch ex As Exception
            RichTextBox1.Text += ControlChars.CrLf & "ERROR: " & ex.Message
        End Try
    End Function

    Function Receive()
        Dim scanstring As String
        Dim buffer(32000) As Byte
        Dim ttlbytes As Integer
        Dim x As Integer

        sock1.Blocking = False
        For x = 1 To 1000
            Try
                ttlbytes = sock1.Receive(buffer, buffer.Length, 0)
            Catch ex As Exception
                'RichTextBox1.Text += "ERROR: " & ex.Message
            End Try
            'Convert this received message from a byte array to an easier to
use string
            If ttlbytes > 0 Then
                scanstring = System.Text.Encoding.ASCII.GetString(buffer, 0,
ttlbytes)
                RichTextBox1.Text += scanstring
                ttlbytes = 0
            End If
        Next x

    End Function

    Private Function Send()
        'This sub sends a message to the server
        Dim i As Integer
        Dim b(3200) As Byte
        Dim message As String = TextBox1.Text + ControlChars.CrLf
        'Take what the user typed and convert it to a byte array so the
socket can send it
        For i = 1 To message.Length
            b(i) = Asc(Mid(message, i, 1))
        Next
        'Send the message to the server
        Try
            sock1.Blocking = True
            sock1.Send(b)
        Catch ex As Exception
            RichTextBox1.Text += ControlChars.CrLf & "ERROR: " & ex.Message
        End Try
    End Function

    Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged

    End Sub
End Class



Thu, 21 Jul 2005 09:39:16 GMT  
 Problem with my VB.NET telnet client
This is a VB 'classic' newsgroup.

Please post .net questions to the microsoft newsgroups devoted exclusively
to .net programming (server: msnews.microsoft.com). Look for newsgroups with
the word "dotnet" or "vsnet" in their name, e.g.
microsoft.public.dotnet.general, microsoft.public.dotnet.languages.vb.

--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.


# (((To REPLY to my message, please remove the xyz from my email name:

#
# I simplified my VB.NET telnet client code for troubleshooting and I use
MUD
# servers for testing it. You can compile and run this code to see the
problem
# (NOTE: To run it, you need a form1 with a richtextbox1, a textbox1, and
two
# buttons.).
#
# It has the following problem:
#
# The client connects to all servers and receives their welcome messages
just
# fine. But on some servers, after I get the welcome message and try to
# respond with login text or whatever is requested, the server just sits
there
# like it never got my message. In the code comments below, I list two MUD
# server addresses, one that works correctly and one that fails. I am really
# stuck, any ideas would be greatly appreciated. Thanks!
#
# Imports System.Net
# Imports System.Net.Sockets
#
# Public Class Form1
#     Inherits System.Windows.Forms.Form
#
#     Dim sock1 As New Socket(AddressFamily.InterNetwork, SocketType.Stream,
# ProtocolType.Tcp)
#
#     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
# System.EventArgs) Handles Button2.Click
#         'This is the connect button
#         Connect()
#         Button2.Enabled = False
#         Receive()
#     End Sub
#
#     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
# System.EventArgs) Handles Button1.Click
#         'This is the send button
#         Send()
#         TextBox1.Text = ""
#         Receive()
#     End Sub
#
#     Private Function Connect()
#         'BAD connection example = 206.245.158.190 5000
#         'GOOD connection example = 63.205.237.177 1912
#         Dim myIP As IPAddress = IPAddress.Parse("63.205.237.177")
#         'Parse the port number from the end of the string in the combobox
#         Dim EPhost As New IPEndPoint(myIP, 1912)
#         'Catch errors trying to connect to hosts that may not be there
#         Try
#             sock1.Connect(EPhost)
#         Catch ex As Exception
#             RichTextBox1.Text += ControlChars.CrLf & "ERROR: " &
ex.Message
#         End Try
#     End Function
#
#     Function Receive()
#         Dim scanstring As String
#         Dim buffer(32000) As Byte
#         Dim ttlbytes As Integer
#         Dim x As Integer
#
#         sock1.Blocking = False
#         For x = 1 To 1000
#             Try
#                 ttlbytes = sock1.Receive(buffer, buffer.Length, 0)
#             Catch ex As Exception
#                 'RichTextBox1.Text += "ERROR: " & ex.Message
#             End Try
#             'Convert this received message from a byte array to an easier
to
# use string
#             If ttlbytes > 0 Then
#                 scanstring = System.Text.Encoding.ASCII.GetString(buffer,
0,
# ttlbytes)
#                 RichTextBox1.Text += scanstring
#                 ttlbytes = 0
#             End If
#         Next x
#
#     End Function
#
#     Private Function Send()
#         'This sub sends a message to the server
#         Dim i As Integer
#         Dim b(3200) As Byte
#         Dim message As String = TextBox1.Text + ControlChars.CrLf
#         'Take what the user typed and convert it to a byte array so the
# socket can send it
#         For i = 1 To message.Length
#             b(i) = Asc(Mid(message, i, 1))
#         Next
#         'Send the message to the server
#         Try
#             sock1.Blocking = True
#             sock1.Send(b)
#         Catch ex As Exception
#             RichTextBox1.Text += ControlChars.CrLf & "ERROR: " &
ex.Message
#         End Try
#     End Function
#
#     Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object,
# ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
#
#     End Sub
# End Class
#
#
#
#



Thu, 21 Jul 2005 12:57:54 GMT  
 Problem with my VB.NET telnet client
I figured out what I did wrong.

I wasn't handling the bye array correctly. I didn't realize it was
zero-based and as a result, I was accidentally sending all my messages to
the server with a NULL chr(0) attached to the front. Some servers could
handle it and others couldn't, thus the weird inconsistent results.

Thanks!


Quote:
> This is a VB 'classic' newsgroup.

> Please post .net questions to the microsoft newsgroups devoted exclusively
> to .net programming (server: msnews.microsoft.com). Look for newsgroups
with
> the word "dotnet" or "vsnet" in their name, e.g.
> microsoft.public.dotnet.general, microsoft.public.dotnet.languages.vb.

> --

> Randy Birch
> MVP Visual Basic
> http://www.mvps.org/vbnet/
> Please respond only to the newsgroups so all can benefit.



> # (((To REPLY to my message, please remove the xyz from my email name:

> #
> # I simplified my VB.NET telnet client code for troubleshooting and I use
> MUD
> # servers for testing it. You can compile and run this code to see the
> problem
> # (NOTE: To run it, you need a form1 with a richtextbox1, a textbox1, and
> two
> # buttons.).
> #
> # It has the following problem:
> #
> # The client connects to all servers and receives their welcome messages
> just
> # fine. But on some servers, after I get the welcome message and try to
> # respond with login text or whatever is requested, the server just sits
> there
> # like it never got my message. In the code comments below, I list two MUD
> # server addresses, one that works correctly and one that fails. I am
really
> # stuck, any ideas would be greatly appreciated. Thanks!
> #
> # Imports System.Net
> # Imports System.Net.Sockets
> #
> # Public Class Form1
> #     Inherits System.Windows.Forms.Form
> #
> #     Dim sock1 As New Socket(AddressFamily.InterNetwork,
SocketType.Stream,
> # ProtocolType.Tcp)
> #
> #     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
> # System.EventArgs) Handles Button2.Click
> #         'This is the connect button
> #         Connect()
> #         Button2.Enabled = False
> #         Receive()
> #     End Sub
> #
> #     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> # System.EventArgs) Handles Button1.Click
> #         'This is the send button
> #         Send()
> #         TextBox1.Text = ""
> #         Receive()
> #     End Sub
> #
> #     Private Function Connect()
> #         'BAD connection example = 206.245.158.190 5000
> #         'GOOD connection example = 63.205.237.177 1912
> #         Dim myIP As IPAddress = IPAddress.Parse("63.205.237.177")
> #         'Parse the port number from the end of the string in the
combobox
> #         Dim EPhost As New IPEndPoint(myIP, 1912)
> #         'Catch errors trying to connect to hosts that may not be there
> #         Try
> #             sock1.Connect(EPhost)
> #         Catch ex As Exception
> #             RichTextBox1.Text += ControlChars.CrLf & "ERROR: " &
> ex.Message
> #         End Try
> #     End Function
> #
> #     Function Receive()
> #         Dim scanstring As String
> #         Dim buffer(32000) As Byte
> #         Dim ttlbytes As Integer
> #         Dim x As Integer
> #
> #         sock1.Blocking = False
> #         For x = 1 To 1000
> #             Try
> #                 ttlbytes = sock1.Receive(buffer, buffer.Length, 0)
> #             Catch ex As Exception
> #                 'RichTextBox1.Text += "ERROR: " & ex.Message
> #             End Try
> #             'Convert this received message from a byte array to an
easier
> to
> # use string
> #             If ttlbytes > 0 Then
> #                 scanstring =

System.Text.Encoding.ASCII.GetString(buffer,

- Show quoted text -

Quote:
> 0,
> # ttlbytes)
> #                 RichTextBox1.Text += scanstring
> #                 ttlbytes = 0
> #             End If
> #         Next x
> #
> #     End Function
> #
> #     Private Function Send()
> #         'This sub sends a message to the server
> #         Dim i As Integer
> #         Dim b(3200) As Byte
> #         Dim message As String = TextBox1.Text + ControlChars.CrLf
> #         'Take what the user typed and convert it to a byte array so the
> # socket can send it
> #         For i = 1 To message.Length
> #             b(i) = Asc(Mid(message, i, 1))
> #         Next
> #         'Send the message to the server
> #         Try
> #             sock1.Blocking = True
> #             sock1.Send(b)
> #         Catch ex As Exception
> #             RichTextBox1.Text += ControlChars.CrLf & "ERROR: " &
> ex.Message
> #         End Try
> #     End Function
> #
> #     Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object,
> # ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
> #
> #     End Sub
> # End Class
> #
> #
> #
> #



Thu, 21 Jul 2005 13:50:35 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Problem with my VB.NET telnet client

2. VB Source code for telnet client

3. Telnet client in VB - here it is !

4. Need Help getting VB app to Telnet using VT52 or better to HP client

5. Problem posting xml from vb.net client to asp classic page

6. searching SSH2.NET and Telnet.NET controls

7. telnet command in vb.net

8. ftp client application in VB.Net vs VB 6

9. ftp client application in VB.Net vs VB 6

10. Telnet Client

11. Telnet client using QB

12. Visual Basic telnet client

 

 
Powered by phpBB® Forum Software