Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2007

Tip: Looking for answers? Try searching our database.

Slow Transfer Rates on Socket and TCPClient data reads

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew Jackson - 30 Sep 2007 19:17 GMT
I am writing a newsgroup client.  I have the protocol figured out.  But I
get slow transfer speeds off any of the network objects read the data from

For example one of the commands for a news client to use is "XOVER
articlenumber-"

This return string after string of all the news articles from article number
on....

Another newsclient, i wont name names, pulls data down just fine.  Using a
"newsgroup header" accelerator that compresses the headers server side and
transmits then then uncompresses them and delivers them to the client I can
see exactly how much data is being download.  They give the stats of data
transfer speed.  This other program routinely gets speeds of greater than
1Mbps.  It spikes up to 2Mbps and occassionally goes down to 0.5Mbps.  When
I open a connection and issue the proper command to do the same I can see
via the accelerator that  my data read speeds will rarely go over 0.5Mbps
and will actually however from 0.1 to 0.5Mbps for the life of the transfer.

I have tried many different ways.  Using the NetworkStream and a
StreamReader object reading line by line off the stream.  Reading bytes off
the Network Stream object, brought off the TCPClient object.  Working
directly with the Socket object and not the TCPClient object.  I have taken
out any and all extra processing that could be done off the received bytes
just to eliminate string comparisons etc off as a cause of the performance
problem.

I have tried it in VB.Net ... C# ... unmanaged C++ code all return the same
pitiful network transfer rates.

Following is a snippit of code I am using on the VB side to read data off
the stream.

Dim buffer(8000) As Byte
Dim se As SocketError
Dim iRx As Integer
Do While True
 iRx = m_Socket.Receive(buffer, 0, buffer.Length, se)
Loop

I know this is an endless loop at this point but for my testing purposes
this is fine.  There is plenty of data for me to get in the 50 million worth
of lines that this XOVER command is returning to me.

Here is some of the code from the class I am using to create the object.

Private m_Socket As New
System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp)
Private m_strHost As String
Private m_intPort As Integer

Property Host() As String
 Get
   Return m_strHost
 End Get
 Set(ByVal value As String)
   m_strHost = value
 End Set
End Property

Property Port() As Integer
 Get
   Return m_intPort
 End Get
 Set(ByVal value As Integer)
   m_intPort = value
 End Set
End Property

Public Function Connect() As Boolean
 Dim ipAdd As IPAddress = Dns.GetHostEntry(m_strHost).AddressList(0)
 Dim remoteEP As IPEndPoint = New IPEndPoint(ipAdd, m_intPort)
 m_Socket.Connect(remoteEP)
 Return True
End Function

I know I have no error handling in yet but am merely at the testing phase.
I do not know why at this point I have such pitiful transfer rates.  I hope
someone can give me some type of idea.  I can also share some of the other
methods I tried to use to read the data off the various different connection
methods I have tried.  I am about to try with another language... it starts
with a j..... even though I really dont have any desire to use it :)  Please
help

Thanks
Andrew Jackson - 30 Sep 2007 20:53 GMT
Well I wrote the same code in java.  It fluctuates quite a bit transfer wise
but it goes from .5 to 3Mbps.  Mostly staying between 1 and 2 Mbps...

I feel like I must not be doing someting in .Net to optimize my reads and
get the best speed.  I would love it if someone could tell me what it si.

:/

>I am writing a newsgroup client.  I have the protocol figured out.  But I
>get slow transfer speeds off any of the network objects read the data from
[quoted text clipped - 83 lines]
>
> Thanks
Jack Jackson - 30 Sep 2007 23:31 GMT
>Following is a snippit of code I am using on the VB side to read data off
>the stream.
[quoted text clipped - 5 lines]
>  iRx = m_Socket.Receive(buffer, 0, buffer.Length, se)
>Loop

Do you not have Option Strict set to On?

It looks to me like in VS2005 there is no overload of Socket.Receive
with the paramters you are specifying, and that the fourth argument
will be assumed to be a SocketFlags, not a SocketError.

I have no idea what effect if any that might have.
Andrew Jackson - 01 Oct 2007 00:27 GMT
I will check it out... in the mean time I wrote some code that more closely
matches the code I wrote for java...  It also runs slow as molasses.  I have
tried to try to do these things in different ways.  But like I said even
doing it with c++ I still get the same slow transfers.

Imports System.Net.Sockets
Imports System.IO
Module Module1
   Dim socket As Socket = New
System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp)
   Dim ns As NetworkStream
   Dim sr As StreamReader
   Dim sw As StreamWriter
   Sub Main()
       socket.Connect("localhost", 119)
       ns = New NetworkStream(socket)
       sr = New StreamReader(ns)
       sw = New StreamWriter(ns)
       ReadLine()
       SendLine("AUTHINFO USER myusername")
       ReadLine()
       SendLine("AUTHINFO PASS mypassword")
       ReadLine()
       SendLine("GROUP alt.binaries.multimedia")
       Dim strReturn As String = ReadLine()
       Dim artCount As String = strReturn.Split(" ")(1)
       Dim artFirst As String = strReturn.Split(" ")(2)
       Dim artLast As String = strReturn.Split(" ")(3)
       SendLine("XOVER " & artFirst & "-")
       While True
           ReadLine()
       End While
   End Sub
   Public Sub SendLine(ByVal Text As String)
       sw.Write(Text & vbCrLf)
       sw.Flush()
   End Sub
   Public Function ReadLine() As String
       Dim strLine As String
       strLine = sr.ReadLine
       Return strLine
   End Function
End Module

The java code I wrote is the following:
import java.util.Scanner;
import java.io.*;
import java.net.*;
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
class MySocket {
static Socket socket;
static PrintWriter out = null;
static BufferedReader in = null;
public static void main(String[] args) throws Exception
{
 socket = new Socket("localhost", 119);
 out = new PrintWriter(socket.getOutputStream(), true);
 in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

 ReadLine();
 SendLine("AUTHINFO USER myusername");
 ReadLine();
 SendLine("AUTHINFO PASS mypassword");
 ReadLine();
 SendLine("GROUP alt.binaries.multimedia");
 String ret = ReadLine();
 String artCount = ret.split(" ")[1];
 String artFirst = ret.split(" ")[2];
 String artLast = ret.split(" ")[3];
 System.out.println(artCount);
 System.out.println(artFirst);
 System.out.println(artLast);
 SendLine("XOVER " + artFirst + "-");
 boolean flag=true;
 while (flag) {
  ReadLine();
 }
}
public static void SendLine(String text) throws Exception
{
        out.println(text);
}
public static String ReadLine() throws Exception
{
 String line;
 line = in.readLine();
 return line;
}
}

>>Following is a snippit of code I am using on the VB side to read data off
>>the stream.
[quoted text clipped - 13 lines]
>
> I have no idea what effect if any that might have.
Andrew Jackson - 01 Oct 2007 01:14 GMT
I made the correction still it doesnt make a difference.

Seems strange.  I am getting about .1 to .3Mbps with this particular
Receive.

>>Following is a snippit of code I am using on the VB side to read data off
>>the stream.
[quoted text clipped - 13 lines]
>
> I have no idea what effect if any that might have.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.