Ciao a tutti!sono nuovo del forum e confesso di non essere una cima nella programmazione..ho questo problema: devo inviare alcuni comandi (stringhe ASCII) tramite Ethernet a un dispositivo connesso al PC il quale deve darmi un reply a seconda del comando inviato. Sto utilizzando Visual studio 2010 e ho abbozzato il seguente frammento di codice:
Imports System.Net.Sockets
Imports System.Net
Imports System.Text

Module mainModule


Sub connect(ByVal server As [String], ByVal message As [String])
Try
' Create a TcpClient.
' Note, for this client to work you need to have a TcpServer
' connected to the same address as specified by the server, port
' combination.
Dim port As Int32 = 24691
Dim client As New TcpClient(server, port)

' Translate the passed message into ASCII and store it as a Byte array.
Dim data As [Byte]() = Encoding.ASCII.GetBytes(message)
' Get a client stream for reading and writing.
' Stream stream = client.GetStream();
Dim stream As NetworkStream = client.GetStream()
' Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length)

Console.WriteLine("Sent: {0}", message)

' Receive the TcpServer.response.
' Buffer to store the response bytes.
data = New [Byte](128) {}
' String to store the response ASCII representation.
Dim responseData As [String] = ""

' Read the first batch of the TcpServer response bytes.
Dim bytes As Int32 = stream.Read(data, 0, data.Length)
responseData = Encoding.ASCII.GetString(data)
If (responseData = Nothing) Then
Console.WriteLine("No data")
Else : Console.WriteLine("Received: {0}", responseData)
End If


' Close everything.
client.Close()
Catch e As ArgumentNullException
Console.WriteLine("ArgumentNullException: {0}", e)
Catch e As SocketException
Console.WriteLine("SocketException: {0}", e)
End Try

Console.WriteLine(ControlChars.Cr + " Press Enter to continue...")
Console.Read()
End Sub 'Connect

Sub main()
connect("169.254.82.1", "comando generico" + Char.ConvertFromUtf32(13))
End Sub

End Module

In console appare solo la stringa inviata ma in ricezione non vedo assolutamente nulla..qualcuno più esperto sa dirmi dov'è l'inghippo??Grazie a tutti della collaborazione!