本文介绍了从网络流读取数据.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个有关从网络流读取数据的问题.
我正在使用套接字编程在同一台计算机上运行的两个进程之间发送数据.
从过程1写入数据:
Hi Everyone,
I have a question regarding reading data from Network stream.
I am sending data between the two processes which are running on the same machine using Socket Programming.
To write Data from Process 1:
Int32 port = 13000;
TcpClient client = new TcpClient("127.0.0.1", port);
Byte[] data = System.Text.Encoding.ASCII.GetBytes
(WorkReqNbr.ToString());
NetworkStream stream = client.GetStream();
stream.Write(data, 0, data.Length);
stream.Close();
client.Close();
要从流程2中读取数据:
To Read data from Process 2:
Dim nbr As Integer = 0
Dim port As Integer = 13000
Dim localAddr As IPAddress = IPAddress.Parse("127.0.0.1")
server = New TcpListener(localAddr, port)
server.Start()
Dim bytes As [Byte]() = New [Byte](256) {}
Dim data As String = String.Empty
While (True)
Dim client As TcpClient = server.AcceptTcpClient()
data = Nothing
Dim stream As NetworkStream = client.GetStream()
Dim i As Integer
i = stream.Read(bytes, 0, bytes.Length)
data = System.Text.Encoding.ASCII.GetString(bytes)
问题:
在上面的代码中,GetString(bytes)
以以下格式返回值:
数据=测试;
现在,此字符不被视为有效字符串,因为缺少结尾(双引号).
谁能告诉我我要去哪里错了?
预先感谢,
Dilip Kumar V.
Problem:
In the above code GetString(bytes)
returns value in below format:
data = "test ;
Now this is not treated as a valid string because end "(double quote) is missing.
Can any one tell me, where i am going wrong?
Thanks in advance,
Dilip Kumar V.
推荐答案
这篇关于从网络流读取数据.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!