0
我想將圖像發送到連接到我的TCP Listner(服務器)的客戶端。我通過網絡成功發送和接收文本,但無法將圖片從我的服務器發送到客戶端。我想Dislpay放置在客戶端窗口中的PictureBox中的圖片。 這裏是我使用的發送和接收文本但不能想象一個代碼通過TCP Socket發送/接收圖像C#
SERVER:
接收機:
void TListner()
{
try
{
IPEndPoint ipendp = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8080);
TcpListener tl = new TcpListener(ipendp);
tl.Start();
Socket s1 = tl.AcceptSocket(); ;
NetworkStream ns = new NetworkStream(s1);
StreamReader sr = new StreamReader(ns);
while (true)
{
textBox1.Text = sr.ReadLine();
}
}
catch
{
Application.Exit();
}
}
發信人:
MemoryStream ms = new MemoryStream();
sw.Write("TEST STRING");
sw.Flush();
客戶:
接收機:
void TCP_CLIENT()
{
try
{
IPEndPoint ipendp = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8080);
TcpClient tcpc = new TcpClient();
tcpc.Connect(ipendp);
NetworkStream ns = tcpc.GetStream();
StreamReader sr = new StreamReader(ns);
while (true)
{
textBox1.Text = sr.ReadLine();
}
}
catch
{
Application.Exit();
}
我想顯示在一個名爲PBox1在客戶端窗口的PictureBox的圖片。
嘗試在這些鏈接 http://stackoverflow.com/questions/6811760/sending-and-receiving-an-image-file-c HTTP給出的答案://stackoverflow.com/questions/2789294/tcp-client-server-image-transfer –