2012-03-19 35 views
0

我的代码看起来非常类似于这个职位Read bytes from NetworkStream (Hangs),我在下面复制。 (我知道这是C# - 我需要一个VB的解决方案)vb-网络流写只返回第一个结果(需要全部)

 // 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. 

    TcpClient client = new TcpClient(server, port); 

     // Translate the passed message into ASCII and store it as a Byte array. 
     Byte[] data = System.Text.Encoding.ASCII.GetBytes(message); 

     // Get a client stream for reading and writing. 
     NetworkStream stream = 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[256]; 

     // String to store the response ASCII representation. 
     String responseData = String.Empty; 

     // Read the first batch of the TcpServer response bytes. 
     Int32 bytes = stream.Read(data, 0, data.Length); 
     responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes); 

     Console.WriteLine("Received: {0}", responseData); 

     // Close everything. 
     stream.Close(); client.Close(); 

我的问题就在于此:

我有一种形式,它发生在哪个TIF文件(S)用户输入找到(它结束成为getBytes(消息))。当这样做时,它总是返回一个结果 - 第一个符合条件的tif文件。但是,在某些情况下,我知道我应该接受多个匹配。

然后我将结果发送到一个PictureBox,应该能够通过

我已经尝试了一些方法来获得多个结果的结果(其中这部分工作正常)滚动,但也许我错过了明显?我最好的猜测是使用asyncronous beginread/write .... 我试图使用for循环,但我最终得到一堆相同的tif文件作为结果...

任何人都可以帮助我(即使有一个通用的方向)?我不是专业人士。先谢谢您的帮助。

+0

您的发布代码是C#,但你要求VB的帮助? – 2012-03-19 15:08:15

+0

但是你只是发送和接收一条消息..你试过什么?你的代码看起来如何? (真正的).. – gbianchi 2012-03-19 15:11:15

+0

是啊,VB是非常相似..几乎相同..我的缓冲区较大,但因为我的文件可能很大(不固定长度)我试图获取文件并使用forloop – GetBrutal 2012-03-19 15:26:09

回答

0

我最终发现了问题所在。我所寻找的数据不是标准化的,因此结果是一遍又一遍的相同数据。我改变了我正在寻找的东西和tada它的工作。无论如何,感谢您的帮助