Hi, I am working on an intensive application (VB.Net 2003) that uses clientsocket to connect and issue commands to network switches.

The problem I am noticing is that the commands I am trying to send don't send, unless I run the program through the debugger line by line.

The program connects to the switch and logins great.

Any suggestions or reasons why this would occur?

Here is a sample of my code:
'connect to switch via telnet
If uiTelnetRadioButton.Checked = True Then
ClientSocket.Connect(ipAddress, 23)

'login to switch
ClientSocket.SendBytes(userId)
ClientSocket.SendBytes(password)

'determine if switch is IOS or CatOS and enable port
If portIOS = True Then
ClientSocket.SendBytes("conf t" + Chr(13))
ClientSocket.SendBytes("int " & (port) + Chr(13))
ClientSocket.SendBytes("no switchport port-security mac-address" + Chr(13))
ClientSocket.SendBytes("no switchport port-security mac-address sticky" + Chr(13))
ClientSocket.SendBytes("switchport port-security mac-address sticky" + Chr(13))
ClientSocket.SendBytes("exit" + Chr(13))
ClientSocket.SendBytes("exit" + Chr(13))
ClientSocket.SendBytes("wri mem" + Chr(13))
Else 'portCatOS = True
ClientSocket.SendBytes("clear port security " & (port) & " all" + Chr(13))
End If

ClientSocket is another Module that i call there. I found it easier to program this way and keep it more clean. Here is the code from the clientsocket module. At first I used BeginConnect, BeginSend, and BeginReceive...I am now trying just to use the .connect and .send. I found similar code on the internet while coding the clientsocket and used that as a basis.

Imports System.Net
Imports System.Net.Sockets
Imports System.Threading

'socket notification commands
Public Enum NotifyCommand
Connected
SentData
ReceivedData
SocketError
End Enum

Module ClientSocket

'notification event
Public Delegate Sub NotifyEventHandler(ByVal command As NotifyCommand, ByVal data As Object)
Public Event Notify As NotifyEventHandler

'declare variables
Private clientSocket As Socket
Private readBuffer(4095) As Byte
Private disconnecting As Boolean = False
Private ASCII As New System.Text.ASCIIEncoding

Public ReadOnly Property Connected() As Boolean
Get
'return righta way if have not created socket
If clientSocket Is Nothing Then
Return False
End If

'the socket is not connected if connected property is false
If clientSocket.Connected = False Then
Return False
End If

'poll socket to verify connection is connected
Try
Return Not clientSocket.Poll(1, SelectMode.SelectError)
Catch
Return False
End Try
End Get
End Property

Public Sub Connect(ByVal host As String, ByVal port As Integer)
'make sure disconnected from any switches
Disconnect()

'connect to switch
Dim ip As IPAddress = Dns.Resolve(host).AddressList(0)
Dim ipEndPoint As New IPEndPoint(ip, port)
clientSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
clientSocket.Connect(ipEndPoint)
End Sub

Public Sub Disconnect()
'return if a socket is not created
If clientSocket Is Nothing Then
Return
End If

'set disconnecting flag
disconnecting = True

Try
'shutdown socket
clientSocket.Shutdown(SocketShutdown.Both)
Catch
End Try

Try
'close the socket
clientSocket.Close()

Catch
End Try

disconnecting = False
End Sub

Public Sub SendBytes(ByVal data As String)
'send the data
clientSocket.Send(ASCII.GetBytes(data))
End Sub

Public Sub ReceiveBytes()
'receive data
clientSocket.BeginReceive(readBuffer, 0, readBuffer.Length, SocketFlags.None, AddressOf ReceiveCallback, Nothing)
End Sub

Private Sub RaiseNotifyEvent(ByVal command As NotifyCommand, ByVal data As Object)
'don't raise notification events when disconnecting
If disconnecting = False Then
RaiseEvent Notify(command, data)
End If
End Sub

Private Sub ConnectCallBack(ByVal ar As IAsyncResult)
'callback method that is called when connection completes
Try
clientSocket.EndConnect(ar)
RaiseNotifyEvent(NotifyCommand.Connected, Nothing)
Catch ex As Exception
RaiseNotifyEvent(NotifyCommand.SocketError, ex.Message)
End Try
End Sub

Private Sub SendCallback(ByVal ar As IAsyncResult)
'callback method that is called when send completes
Try
clientSocket.EndSend(ar)
RaiseNotifyEvent(NotifyCommand.SentData, Nothing)
Catch ex As Exception
RaiseNotifyEvent(NotifyCommand.SocketError, ex.Message)
End Try
End Sub

Private Sub ReceiveCallback(ByVal ar As IAsyncResult)
'callback method that is called when receive completes
Dim readBuffer(0) As Byte
Try
clientSocket.EndReceive(ar)
' the server sends an acknowledgment back that is stored in the read buffer
If readBuffer(0) = 1 Then
RaiseNotifyEvent(NotifyCommand.ReceivedData, True)
Else
RaiseNotifyEvent(NotifyCommand.ReceivedData, False)
End If
Catch ex As Exception
RaiseNotifyEvent(NotifyCommand.SocketError, ex.Message)
End Try
End Sub
End Module

Thanks in advance. I have used google and can't seem to find someone who has the same problem, but unfortunently no luck.

Mike