zebrone
27-04-2007, 15:28
Ciao a tutti, ho scritto del codice .net che comunica con un PLC tramite socket. Funziona tutto alla perfezione, solo che alla connessione iniziale (quando chiamo il metodo connect della classe TCPclient) devo attendere 4-5 secondi. C'è qualcosa da settare che mi sono perso o è normale?
Public Function Connect(ByVal ip As String, ByVal port As Integer) As Boolean
If Not connected Then
Dim client As TcpClient
Try
client = New TcpClient
client.Connect(ip, port)
client.ReceiveTimeout = 100
client.SendTimeout = 100
connected = True
tc = client
Catch ex As Exception
connected = False
tc = Nothing
End Try
End If
Return connected
End Function
Public Function Connect(ByVal ip As String, ByVal port As Integer) As Boolean
If Not connected Then
Dim client As TcpClient
Try
client = New TcpClient
client.Connect(ip, port)
client.ReceiveTimeout = 100
client.SendTimeout = 100
connected = True
tc = client
Catch ex As Exception
connected = False
tc = Nothing
End Try
End If
Return connected
End Function