473,761 Members | 2,455 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Telnet Client, Sockets trouble!

17 New Member
Hello Everyone!

I have so nearly finished a mud client for a customer to the point where I was about to send them the source code. Out of luck I took the project home to try it on my personal PC just to make sure.

At work on my corporate network everything works perfectly but it seems once anyone uses the client on a direct high speed connection to the internet the incoming text seems to all get jumbled up!

This is using system.net.sock ets namespace i've left out a fair bit of code or this post will probably be too long.

My thinking is that on faster connections the dataarrival event is fired off BEFORE the current text has been displayed leading to the text getting mixed up?

If anyone can offer some suggestions here it would be massively appreciated as once this issue is resolved the project works perfectly, its also intended that the client will be provided free of charge to everyone so by helping me your helping people get free software!

Heres the source below...
Expand|Select|Wrap|Line Numbers
  1. Dim evtDataArrival As New AsyncCallback(AddressOf  Datarrive)
  2. Public tcpClient As New System.Net.Sockets.TcpClient()
  3. Dim buffer(1024) As Byte
  4. Dim stream As NetworkStream
  5. stream = tcpClient.GetStream
  6.  
  7.  
  8.  
  9. Private Function dataArrive(ByVal dr As IAsyncResult)
  10.         Dim textin As String
  11.  
  12.         numberOfBytes = stream.EndRead(dr)
  13.         ' At this instant DataBuffer variable is filled with the received data
  14.         stream.Flush()
  15.         textin = textin & Encoding.ASCII.GetString(buffer, 0, numberOfBytes)
  16.  
  17.         While stream.DataAvailable
  18.             stream.BeginRead(buffer, 0, 1024, New AsyncCallback(AddressOf dataArrive), stream)
  19.         End While
  20.  
  21.         If Not stream.DataAvailable Or Asc(Strings.Right(textin, 1)) = Val(Chr(32)) Then
  22.             param = textin
  23.             Settext(textin)
  24.             words.Add(textin)
  25.             param = ""
  26.  
  27.             If checktrig.IsAlive = False Then
  28.                 checktrig.Interrupt()
  29.             End If
  30.  
  31.             stream.BeginRead(buffer, 0, 1024, evtDataArrival, Nothing)
  32.  
  33.         Else
  34.             stream.BeginRead(buffer, 0, 1024, evtDataArrival, Nothing)
  35.         End If
  36.  
  37.     End Function
  38.  
  39.  Private Function Settext(ByVal param As String) As String
  40.         Dim networkStream As NetworkStream = tcpClient.GetStream()
  41.         Dim pos As Integer
  42.         Dim pos2
  43.         Dim esccode As String
  44.         Dim i As Integer
  45.         Dim parse As String
  46.         Dim myregex As New Regex("(?s)(?:\e\[(?:(\d+);?)*([A-Za-z])(.*?))")
  47.         Dim myresults As MatchCollection
  48.         '(?=\e\[|\z)
  49.  
  50.         If Me.RichTextBox1.InvokeRequired Then
  51.             Dim d As New Stt(AddressOf Settext)
  52.             RichTextBox1.Invoke(d, param)
  53.         Else
  54.             i = 0
  55.             pos = 1
  56.             myresults = myregex.Matches(Trim(param))
  57.  
  58.             If myresults.Count > 0 Then
  59.                 Do Until pos = param.Length
  60.  
  61.                     If i <> myresults.Count Then
  62.                         esccode = myresults(i).Value
  63.                         parse = Strings.Mid(param, pos, IIf(myresults(i).Index <= pos, (myresults(i).Index - (pos - 1)), (myresults(i).Index - pos)) + 1)
  64.                     Else
  65.                         parse = Strings.Mid(param, pos, param.Length)
  66.                         pos = param.Length
  67.  
  68.                     End If
  69.  
  70.                     If Not Strings.Left(parse, 1) = Chr(27) Then
  71.                         Me.RichTextBox1.SelectionColor = vcolour
  72.                         RichTextBox1.AppendText(parse)
  73.                         SendMessage(RichTextBox1.Handle, WM_VSCROLL, SB_BOTTOM, 0)
  74.                     End If
  75.  
  76.                     If esccode <> "" Then
  77.                         Select Case esccode
  78.                             Case Chr(27) & "[1m"
  79.                                 RichTextBox1.SelectionFont = New Font(RichTextBox1.Font.ToString, RichTextBox1.Font.Size, FontStyle.Bold)
  80.                                 Exit Select
  81.                             Case Chr(27) & "[0m"
  82.                                 RichTextBox1.SelectionFont = New Font(RichTextBox1.Font.ToString, RichTextBox1.Font.Size, FontStyle.Regular)
  83.                                 vcolour = Color.Lime
  84.                                 Exit Select
  85.                             Case Chr(27) & "[33m"
  86.                                 vcolour = Color.Yellow
  87.                                 Exit Select
  88.                             Case Chr(27) & "[35m"
  89.                                 vcolour = Color.Magenta
  90.                                 Exit Select
  91.                             Case Chr(27) & "[36m"
  92.                                 vcolour = Color.Cyan
  93.                                 Exit Select
  94.                         End Select
  95.                     End If
  96.  
  97.                     If i <> myresults.Count Then
  98.                         pos = (myresults(i).Index + Len(esccode)) + 1
  99.                         esccode = ""
  100.                         i = i + 1
  101.                     End If
  102.                 Loop
  103.             Else
  104.                 Me.RichTextBox1.SelectionColor = vcolour
  105.                 RichTextBox1.AppendText(param)
  106.                 SendMessage(RichTextBox1.Handle, WM_VSCROLL, SB_BOTTOM, 0)
  107.             End If
  108.         End If
  109.     End Function
  110.  
Jul 11 '08 #1
2 1737
marcf
17 New Member
As an update i've confirmed its he event firing multiple times while its still trying to display, any ideas on how to make the second firing of the event wait until all previous ones have finished?
Jul 11 '08 #2
Plater
7,872 Recognized Expert Expert
Perhaps buffer a collection of bytes before displaying them.
Like either wait till X amount of bytes have come in or 0.5seconds have passed with no data arrival?

I would also recomend cleaning up your parsing code. It's almost all plain VB and not VB.NET, it might make a difference.
Jul 11 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
6469
by: Richard Bird CCNP, CCDP, MCSE, etc. | last post by:
I need some help adding multithreading to an existing python script. The script was developed to telnet and make changes on a list of cisco routers. I figure that by adding multithreading, I'd be able to telnet to several routers concurrently and speed up the process of making changes. Is this feasible using python with its standard telnet lib?
0
1569
by: Fu Chen | last post by:
Hi pals! One of my client have a old UNIX application (but very important), it use telnet to operate. I am designing a web interface to this client. one of the work is building the UNIX application in a better interface. I try not to change any code in the old system for I don't want to take response for any trouble in their core system. Is there any trick to wrap the telnet in web environment? For example, i write a gateway in web...
5
33879
by: Greg Martz | last post by:
I'd like to do the following in C# and prefer using tcpclient rather than raw sockets... Connect to a unix box Login run date +%H%M%S retrieve the response. That's it, nothing more. This shouldn't be too complicated, I thought... I have yet to find any examples of being able to do this.
7
14098
by: Rex Winn | last post by:
I've Googled until my eyes hurt looking for a way to issue Telnet commands from C# and cannot find anything but $300 libraries that encapsulate it for you. I don't want to be able to create a Telnet client. I just need to send a telnet request to a local IP address on a LAN issue a "c" then a "b" and stream back the text for internal use. The "c" changes sub-menus and the "b" is a switch to dump the status of a firewall. I need to issue...
2
15782
by: b00x | last post by:
Hi, I'm trying to develop a script that I can reuse to run remote commands on multiple UNIX servers via telnet. I've tried various php scripts after googling for a good 5 or so hours, but found no luck. I've created a script (suprisingly) similar to the on found an old post from 2001...
3
6690
by: jtagpgmr | last post by:
I need help coming up with a way to create a c# program to help me Telnet to a hostIP.. Any suggestions.. or a way to start..
0
3860
by: goroth | last post by:
I am trying to create a telnet client that will connect to several of my network devices on campus and change settings on the devices. So far I can connect with the code below, but I can't seem to get the correct return data from the device. Sometimes I get about 100 bytes and other times I get 3000 bytes. I even put a thread sleep but that still give me different return data from different devices. I know I am going to have to use an...
3
3652
by: =?Utf-8?B?cGlja2VkYW5hbWU=?= | last post by:
Hi, I am trying to establish a telnet session to do screen scraping. This device returns some custom escape sequences, which I can ignore, and some standard escape seq's. At your suggestion, I used Ethereal and netcap.exe. On negotiation the server requests ECHO, and also BINARY. When submitting username, it echos back every charactor I type as I type it. The password gets an ack on every char typed, but not an echo. After that, echo...
6
6152
by: =?Utf-8?B?U2hhcmllZg==?= | last post by:
Dear All, I must write a client program in C# which will communicate with a switch throught telnet. When I create a socket connection on port 22, the switch responds with some text and at the end with some unreadable characters. I found out that the operating system of the switch is redhat and the protocol = SSH-2.0-openssh_3.9p1. My problem:
0
10123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9975
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9909
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8794
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7342
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6623
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3481
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2765
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.