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... -
Dim evtDataArrival As New AsyncCallback(AddressOf Datarrive)
-
Public tcpClient As New System.Net.Sockets.TcpClient()
-
Dim buffer(1024) As Byte
-
Dim stream As NetworkStream
-
stream = tcpClient.GetStream
-
-
-
-
Private Function dataArrive(ByVal dr As IAsyncResult)
-
Dim textin As String
-
-
numberOfBytes = stream.EndRead(dr)
-
' At this instant DataBuffer variable is filled with the received data
-
stream.Flush()
-
textin = textin & Encoding.ASCII.GetString(buffer, 0, numberOfBytes)
-
-
While stream.DataAvailable
-
stream.BeginRead(buffer, 0, 1024, New AsyncCallback(AddressOf dataArrive), stream)
-
End While
-
-
If Not stream.DataAvailable Or Asc(Strings.Right(textin, 1)) = Val(Chr(32)) Then
-
param = textin
-
Settext(textin)
-
words.Add(textin)
-
param = ""
-
-
If checktrig.IsAlive = False Then
-
checktrig.Interrupt()
-
End If
-
-
stream.BeginRead(buffer, 0, 1024, evtDataArrival, Nothing)
-
-
Else
-
stream.BeginRead(buffer, 0, 1024, evtDataArrival, Nothing)
-
End If
-
-
End Function
-
-
Private Function Settext(ByVal param As String) As String
-
Dim networkStream As NetworkStream = tcpClient.GetStream()
-
Dim pos As Integer
-
Dim pos2
-
Dim esccode As String
-
Dim i As Integer
-
Dim parse As String
-
Dim myregex As New Regex("(?s)(?:\e\[(?:(\d+);?)*([A-Za-z])(.*?))")
-
Dim myresults As MatchCollection
-
'(?=\e\[|\z)
-
-
If Me.RichTextBox1.InvokeRequired Then
-
Dim d As New Stt(AddressOf Settext)
-
RichTextBox1.Invoke(d, param)
-
Else
-
i = 0
-
pos = 1
-
myresults = myregex.Matches(Trim(param))
-
-
If myresults.Count > 0 Then
-
Do Until pos = param.Length
-
-
If i <> myresults.Count Then
-
esccode = myresults(i).Value
-
parse = Strings.Mid(param, pos, IIf(myresults(i).Index <= pos, (myresults(i).Index - (pos - 1)), (myresults(i).Index - pos)) + 1)
-
Else
-
parse = Strings.Mid(param, pos, param.Length)
-
pos = param.Length
-
-
End If
-
-
If Not Strings.Left(parse, 1) = Chr(27) Then
-
Me.RichTextBox1.SelectionColor = vcolour
-
RichTextBox1.AppendText(parse)
-
SendMessage(RichTextBox1.Handle, WM_VSCROLL, SB_BOTTOM, 0)
-
End If
-
-
If esccode <> "" Then
-
Select Case esccode
-
Case Chr(27) & "[1m"
-
RichTextBox1.SelectionFont = New Font(RichTextBox1.Font.ToString, RichTextBox1.Font.Size, FontStyle.Bold)
-
Exit Select
-
Case Chr(27) & "[0m"
-
RichTextBox1.SelectionFont = New Font(RichTextBox1.Font.ToString, RichTextBox1.Font.Size, FontStyle.Regular)
-
vcolour = Color.Lime
-
Exit Select
-
Case Chr(27) & "[33m"
-
vcolour = Color.Yellow
-
Exit Select
-
Case Chr(27) & "[35m"
-
vcolour = Color.Magenta
-
Exit Select
-
Case Chr(27) & "[36m"
-
vcolour = Color.Cyan
-
Exit Select
-
End Select
-
End If
-
-
If i <> myresults.Count Then
-
pos = (myresults(i).Index + Len(esccode)) + 1
-
esccode = ""
-
i = i + 1
-
End If
-
Loop
-
Else
-
Me.RichTextBox1.SelectionColor = vcolour
-
RichTextBox1.AppendText(param)
-
SendMessage(RichTextBox1.Handle, WM_VSCROLL, SB_BOTTOM, 0)
-
End If
-
End If
-
End Function
-
2 1737
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?
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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?
|
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...
|
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.
|
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...
|
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...
| |
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..
|
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...
|
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...
|
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:
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| | |