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.sockets 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 1709
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?
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
|
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...
|
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,...
|
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...
| | |