473,411 Members | 2,068 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,411 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 2885
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
0
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,...
0
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...
0
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...
0
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,...
0
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...

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.