Mark82 Posted July 20, 2003 Posted July 20, 2003 (edited) I wrote this code to try and connect to a tcp server, send a string and then recieve the reply string. But it seems that the 'TCPClient.Connect(HostIP, PortNum)' line seems to be taking about 5-6 seconds. where as if i use VB6 and Winsock control it takes 0.5-1 seconds to connect. Is there some way i can get that same sort of performance out of .net?? Thanks for any help. Dim TCPClient As New TcpClient Try TCPClient.Connect(HostIP, PortNum) Catch ex As Exception MsgBox(ex.Message) Exit Function End Try Dim networkStream As NetworkStream = TCPClient.GetStream() If networkStream.CanWrite And networkStream.CanRead Then Dim sendBytes As [byte]() = Encoding.ASCII.GetBytes("@01EX E5 00:52" & vbCr) networkStream.Write(sendBytes, 0, sendBytes.Length) Dim bytes(TCPClient.ReceiveBufferSize) As Byte networkStream.Read(bytes, 0, CInt(TCPClient.ReceiveBufferSize)) Dim returndata As String = Encoding.ASCII.GetString(bytes) Return (returndata) Else If Not networkStream.CanRead Then 'Console.WriteLine("cannot not write data to this stream") TCPClient.Close() Else If Not networkStream.CanWrite Then 'Console.WriteLine("cannot read data from this stream") TCPClient.Close() End If End If End If TCPClient.Close() End Function Edited July 20, 2003 by Mark82 Quote
Administrators PlausiblyDamp Posted July 21, 2003 Administrators Posted July 21, 2003 (edited) Do you get the performance difference from VB.Net and VB 6 running from the same machine? Can't see any obvious reason why it should be so slow - also never experienced any delays in using the connect method myself though. Edited July 21, 2003 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.