祝大家新年发财---问个问题--socket发送结构,接受以后读取的问题
定义变量
Private th As Thread
Private tcpl As TcpListener
Private listenerRun As Boolean = True
定义结构
Public Structure Content
Public username As String
Public passworld As String
Public image_1 As System.Drawing.Image
End Structure
发送函数代码:
Private Sub Send()
Try
Dim msg_1 As Content
msg_1.username = "username "
msg_1.passworld = "passworld "
msg_1.image_1 = Me.PictureBox1.Image
Dim tcpc As New TcpClient(textBox1.Text, 9999)
Dim tcpStream As NetworkStream = tcpc.GetStream()
Dim reqStreamW As New StreamWriter(tcpStream)
reqStreamW.Write(msg_1.username)
reqStreamW.Write(msg_1.passworld)
reqStreamW.Write(msg_1.image_1)
reqStreamW.Flush()
tcpStream.Close()
tcpc.Close()
Catch ex As Exception
ToolStripStatusLabel1.Text = "目标计算机拒绝连接请求!"
MessageBox.Show(ex.Message)
End Try
End Sub
接收函数代码:
Private Sub Listen()
Try
tcpl = New System.Net.Sockets.TcpListener(5656)
tcpl.Start()
ToolStripStatusLabel1.Text = "正在监听..."
While listenerRun
Dim s As Socket = tcpl.AcceptSocket()
Dim stream(1024) As Byte
Dim i As Integer = s.Receive(stream)
MessageBox.Show(i.ToString)
Dim ddd As New Content
ddd.username = System.Text.Encoding.UTF8.GetString(stream, 0, 10)
ddd.passworld = System.Text.Encoding.UTF8.GetString(stream, 10, 10)
MessageBox.Show(ddd.username + ddd.passworld)
'怎么把传过来的结构中的图片读出来?
'
End While
Catch ex As System.Security.SecurityException
MessageBox.Show("防火墙安全错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Catch ex As Exception
ToolStripStatusLabel1.Text = "已停止监听" + ex.Message.ToString
MessageBox.Show(ex.Message)
End Try
End Sub
问题:
怎么把传过来的结构中的图片读出来?
====================================附件======================================
紧急公告:
一股来自西伯利亚的强冷空气即将影响我国,本周内我大部分地区将出现低温降水天气,请广大朋友做好御寒保暖工作,有老婆的抱老婆,有老公的抱老公。暂时没有老婆(或老公)的请抱暖水壶,请勿乱抱动物,以防患禽流感。
祝圆蛋快乐!