473,320 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Tcp/Ip echo speed

I wrote a VB.net "echo" program using the Tcp client/listener class to
determine how fast the transactions would occur. I got a speed of about 160
echoes per second. A friend did the same test using Linux/C++ and reported
3000 echoes/second. Is my number typical, or am I doing something wrong? How
fast should I expect an echo test to run?

Thanks, Hamil.

Nov 21 '05 #1
4 2875
I'm not sure about the speed difference "should" be but if the code is
simple enough, post it and we can see if you are doing something that could
be slowing it down.

Chris

"hamil" <ha***@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
I wrote a VB.net "echo" program using the Tcp client/listener class to
determine how fast the transactions would occur. I got a speed of about
160
echoes per second. A friend did the same test using Linux/C++ and
reported
3000 echoes/second. Is my number typical, or am I doing something wrong?
How
fast should I expect an echo test to run?

Thanks, Hamil.

Nov 21 '05 #2
I'm not sure about the speed difference "should" be but if the code is
simple enough, post it and we can see if you are doing something that could
be slowing it down.

Chris

"hamil" <ha***@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
I wrote a VB.net "echo" program using the Tcp client/listener class to
determine how fast the transactions would occur. I got a speed of about
160
echoes per second. A friend did the same test using Linux/C++ and
reported
3000 echoes/second. Is my number typical, or am I doing something wrong?
How
fast should I expect an echo test to run?

Thanks, Hamil.

Nov 21 '05 #3

Chris.. I have a bit of egg on my face.

In the process of getting the code ready to post, I made a slight change.
In the code below I have a tr.sleep(1) in both the server and client. I would
have thought that this might limit the speed to around 500 transactions/sec
but in fact it is reduced to about 100 transactions per second. When I take
out the tr.sleep(1) statements, the transaction rate increases to about 1200
per second, much more acceptable.

However I wonder if having these threads working 100% will it slow down
other parts of the program.

Below are two programs. First is the TcpServer. This program waits for a
connection and merely echoes the message it receives.

The second program is the TcpClient. It makes a connection with the
TcpServer and then enters a loop that sends a message, waits for the response
and loops over and over. The message starts with a count so you can see how
fast the echoing is working.
Once everything is working, the key server code snippet is as follows..
Do While listening = True
Thread.Sleep(1)
receivedData = sr.ReadLine
If receivedData <> Nothing Then
returnedData = receivedData.ToUpper
sw.WriteLine(returnedData)
sw.Flush()
End If
Loop

The key client code snippit is.....

Do While Running = 1
'sw.WriteLine(txtSendData.Text)
sw.WriteLine(Format(cnt, "0") & txtSendData.Text)
cnt += 1
sw.Flush()
' Receive and display data.
result = sr.ReadLine()
txtReceiveData.Text = result
tr.Sleep(1)
Loop

****** Start of TcpServer *******

Imports System.IO
Imports System.net
Imports System.Net.Sockets
Imports System.Threading

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

'I did not include the windows generated code.. Hamil.

#End Region

Dim listening As Boolean
Dim localhostAddress As IPAddress
Dim port As Integer
Dim tcpList As TcpListener
Dim tcpCli As TcpClient
Dim ns As NetworkStream
Dim sr As StreamReader
Dim receivedData As String
Dim returnedData As String
Dim sw As StreamWriter

Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butStart.Click
butStart.Enabled = False
butStop.Enabled = True
Dim tr As New Thread(AddressOf ListenToClients)
tr.Start()
End Sub

Sub ListenToClients()
localhostAddress = IPAddress.Parse("192.168.1.20") '.Loopback
port = CInt(txtPort.Text)
tcpList = New TcpListener(localhostAddress, port)
tcpList.Start()
listening = True
Do While listening
Do While tcpList.Pending = False And listening = True
Thread.Sleep(10)
Loop
If Not listening Then Exit Do
Dim tcpCli As New TcpClient
tcpCli = tcpList.AcceptTcpClient()
ns = tcpCli.GetStream
sr = New StreamReader(ns)
sw = New StreamWriter(ns)
tbStatus.Text = "connected"
Do While listening = True
Thread.Sleep(1)
receivedData = sr.ReadLine
If receivedData <> Nothing Then
returnedData = receivedData.ToUpper
sw.WriteLine(returnedData)
sw.Flush()
End If
Loop
sr.Close()
sw.Close()
ns.Close()
tcpCli.Close()
tbStatus.Text = "closed"
Loop
tcpList.Stop()
End Sub

Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butStop.Click
butStart.Enabled = True
butStop.Enabled = False
listening = False
End Sub

Private Sub butStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butStart.Click

End Sub

Private Sub butExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butExit.Click
End
End Sub
End Class

******* End of TcpServer ********

******* Start of TcpClient *******
Imports System.IO
Imports System.Net.Sockets
Imports System.Threading

#Region " Windows Form Designer generated code "

'I did not include this code. Hamil.

#End Region

Public Class TCPClientForm
Inherits System.Windows.Forms.Form
Dim host As String
Dim port As Integer
Dim tcpCli As TcpClient
Dim ns As NetworkStream
Dim sw As StreamWriter
Dim sr As StreamReader
Dim result As String

Dim cnt As Integer = 0

Dim tr As Thread
Dim Running As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
host = txtHost.Text
port = CInt(txtPort.Text)

tcpCli = New TcpClient(host, port)

ns = tcpCli.GetStream

' Send data to the server.
sw = New StreamWriter(ns)
sr = New StreamReader(ns)

sw.WriteLine(txtSendData.Text)
sw.Flush()
' Receive and display data.
result = sr.ReadLine()
txtReceiveData.Text = result
sr.Close()
sw.Close()
ns.Close()
End Sub

Private Sub butConnect_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butConnect.Click
host = txtHost.Text
port = CInt(txtPort.Text)

tcpCli = New TcpClient(host, port)

ns = tcpCli.GetStream

' Send data to the server.
sw = New StreamWriter(ns)
sr = New StreamReader(ns)
End Sub

Private Sub butSend_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butSend.Click

'sw.WriteLine(txtSendData.Text)
sw.WriteLine(Format(cnt, "0") & txtSendData.Text)
cnt += 1
sw.Flush()
' Receive and display data.
result = sr.ReadLine()
txtReceiveData.Text = result
End Sub

Private Sub butClose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butClose.Click
sr.Close()
sw.Close()
ns.Close()

End Sub

Private Sub butStartFast_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butStartFast.Click
Dim tr As New Thread(AddressOf SendFast)
tr.Start()
End Sub

Sub SendFast()
Running = 1
Do While Running = 1
'sw.WriteLine(txtSendData.Text)
sw.WriteLine(Format(cnt, "0") & txtSendData.Text)
cnt += 1
sw.Flush()
' Receive and display data.
result = sr.ReadLine()
txtReceiveData.Text = result
tr.Sleep(1)
Loop
End Sub

Private Sub butStopFast_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butStopFast.Click
Running = 0
End Sub

Private Sub butExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butExit.Click
End
End Sub
End Class

******** End of TcpClient ***********


"Chris, Master of All Things Insignifican" wrote:
I'm not sure about the speed difference "should" be but if the code is
simple enough, post it and we can see if you are doing something that could
be slowing it down.

Chris

"hamil" <ha***@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
I wrote a VB.net "echo" program using the Tcp client/listener class to
determine how fast the transactions would occur. I got a speed of about
160
echoes per second. A friend did the same test using Linux/C++ and
reported
3000 echoes/second. Is my number typical, or am I doing something wrong?
How
fast should I expect an echo test to run?

Thanks, Hamil.


Nov 21 '05 #4

Chris.. I have a bit of egg on my face.

In the process of getting the code ready to post, I made a slight change.
In the code below I have a tr.sleep(1) in both the server and client. I would
have thought that this might limit the speed to around 500 transactions/sec
but in fact it is reduced to about 100 transactions per second. When I take
out the tr.sleep(1) statements, the transaction rate increases to about 1200
per second, much more acceptable.

However I wonder if having these threads working 100% will it slow down
other parts of the program.

Below are two programs. First is the TcpServer. This program waits for a
connection and merely echoes the message it receives.

The second program is the TcpClient. It makes a connection with the
TcpServer and then enters a loop that sends a message, waits for the response
and loops over and over. The message starts with a count so you can see how
fast the echoing is working.
Once everything is working, the key server code snippet is as follows..
Do While listening = True
Thread.Sleep(1)
receivedData = sr.ReadLine
If receivedData <> Nothing Then
returnedData = receivedData.ToUpper
sw.WriteLine(returnedData)
sw.Flush()
End If
Loop

The key client code snippit is.....

Do While Running = 1
'sw.WriteLine(txtSendData.Text)
sw.WriteLine(Format(cnt, "0") & txtSendData.Text)
cnt += 1
sw.Flush()
' Receive and display data.
result = sr.ReadLine()
txtReceiveData.Text = result
tr.Sleep(1)
Loop

****** Start of TcpServer *******

Imports System.IO
Imports System.net
Imports System.Net.Sockets
Imports System.Threading

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

'I did not include the windows generated code.. Hamil.

#End Region

Dim listening As Boolean
Dim localhostAddress As IPAddress
Dim port As Integer
Dim tcpList As TcpListener
Dim tcpCli As TcpClient
Dim ns As NetworkStream
Dim sr As StreamReader
Dim receivedData As String
Dim returnedData As String
Dim sw As StreamWriter

Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butStart.Click
butStart.Enabled = False
butStop.Enabled = True
Dim tr As New Thread(AddressOf ListenToClients)
tr.Start()
End Sub

Sub ListenToClients()
localhostAddress = IPAddress.Parse("192.168.1.20") '.Loopback
port = CInt(txtPort.Text)
tcpList = New TcpListener(localhostAddress, port)
tcpList.Start()
listening = True
Do While listening
Do While tcpList.Pending = False And listening = True
Thread.Sleep(10)
Loop
If Not listening Then Exit Do
Dim tcpCli As New TcpClient
tcpCli = tcpList.AcceptTcpClient()
ns = tcpCli.GetStream
sr = New StreamReader(ns)
sw = New StreamWriter(ns)
tbStatus.Text = "connected"
Do While listening = True
Thread.Sleep(1)
receivedData = sr.ReadLine
If receivedData <> Nothing Then
returnedData = receivedData.ToUpper
sw.WriteLine(returnedData)
sw.Flush()
End If
Loop
sr.Close()
sw.Close()
ns.Close()
tcpCli.Close()
tbStatus.Text = "closed"
Loop
tcpList.Stop()
End Sub

Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butStop.Click
butStart.Enabled = True
butStop.Enabled = False
listening = False
End Sub

Private Sub butStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butStart.Click

End Sub

Private Sub butExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butExit.Click
End
End Sub
End Class

******* End of TcpServer ********

******* Start of TcpClient *******
Imports System.IO
Imports System.Net.Sockets
Imports System.Threading

#Region " Windows Form Designer generated code "

'I did not include this code. Hamil.

#End Region

Public Class TCPClientForm
Inherits System.Windows.Forms.Form
Dim host As String
Dim port As Integer
Dim tcpCli As TcpClient
Dim ns As NetworkStream
Dim sw As StreamWriter
Dim sr As StreamReader
Dim result As String

Dim cnt As Integer = 0

Dim tr As Thread
Dim Running As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
host = txtHost.Text
port = CInt(txtPort.Text)

tcpCli = New TcpClient(host, port)

ns = tcpCli.GetStream

' Send data to the server.
sw = New StreamWriter(ns)
sr = New StreamReader(ns)

sw.WriteLine(txtSendData.Text)
sw.Flush()
' Receive and display data.
result = sr.ReadLine()
txtReceiveData.Text = result
sr.Close()
sw.Close()
ns.Close()
End Sub

Private Sub butConnect_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butConnect.Click
host = txtHost.Text
port = CInt(txtPort.Text)

tcpCli = New TcpClient(host, port)

ns = tcpCli.GetStream

' Send data to the server.
sw = New StreamWriter(ns)
sr = New StreamReader(ns)
End Sub

Private Sub butSend_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butSend.Click

'sw.WriteLine(txtSendData.Text)
sw.WriteLine(Format(cnt, "0") & txtSendData.Text)
cnt += 1
sw.Flush()
' Receive and display data.
result = sr.ReadLine()
txtReceiveData.Text = result
End Sub

Private Sub butClose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butClose.Click
sr.Close()
sw.Close()
ns.Close()

End Sub

Private Sub butStartFast_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butStartFast.Click
Dim tr As New Thread(AddressOf SendFast)
tr.Start()
End Sub

Sub SendFast()
Running = 1
Do While Running = 1
'sw.WriteLine(txtSendData.Text)
sw.WriteLine(Format(cnt, "0") & txtSendData.Text)
cnt += 1
sw.Flush()
' Receive and display data.
result = sr.ReadLine()
txtReceiveData.Text = result
tr.Sleep(1)
Loop
End Sub

Private Sub butStopFast_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butStopFast.Click
Running = 0
End Sub

Private Sub butExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butExit.Click
End
End Sub
End Class

******** End of TcpClient ***********


"Chris, Master of All Things Insignifican" wrote:
I'm not sure about the speed difference "should" be but if the code is
simple enough, post it and we can see if you are doing something that could
be slowing it down.

Chris

"hamil" <ha***@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
I wrote a VB.net "echo" program using the Tcp client/listener class to
determine how fast the transactions would occur. I got a speed of about
160
echoes per second. A friend did the same test using Linux/C++ and
reported
3000 echoes/second. Is my number typical, or am I doing something wrong?
How
fast should I expect an echo test to run?

Thanks, Hamil.


Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: lawrence | last post by:
Right now, over at www.monkeyclaus.org, the following script is getting to the 9th run through and dying after the line: echo "..."; You'll admit that is a strange place to die. I've hit...
6
by: Marco | last post by:
I have a couple pages that have tables, whats best use echo to produce the full table with the variables or is it best to just make the table in plain html and use <?php echo ('$va'l); ?> when i...
13
by: Tony | last post by:
I'm just wondering why it seems most people use "echo" instead of "print". I tend to use "print", probably because I started programming in BASIC back in 78, so it's just familiar. Echo can take...
9
by: Domestos | last post by:
Here an unusual one... Say i am writing a few lines of code in php script as so... <?php echo '<table>'; echo '<tr>'; echo '<td> blah blah </td>'; echo '</tr>'; echo '</table>';
9
by: windandwaves | last post by:
Hi Folk My question is: echo all the time vs echo at the end - what is faster Let me explain I used to write pages like this: echo "<head> ";
0
by: hamil | last post by:
I wrote a VB.net "echo" program using the Tcp client/listener class to determine how fast the transactions would occur. I got a speed of about 160 echoes per second. A friend did the same test...
14
by: Khai | last post by:
I'm an extreme newbie, and have been nosing around the PHP.Net site for a few days. Only, the search function returns alot of information that's not truly relevant due to Coding samples at the...
10
by: M | last post by:
Hi, Suppose you have the situation where you have say 20 blocks of text (~250 chars each) in a MySQL db that you need to display, but each has a condition to check to see whether you should...
32
by: Request-1 | last post by:
hi folks, html coder here, new and terrified * of php!! aaaaaa! i'm trying to bury a JS script to rotate a photo, in a page i converted from html to php. the conversion went well, it was to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.