Socket を使用して vb.net のソケットを介してファイルを転送したい。
質問する
970 次
1 に答える
1
サーバ側:
Do
Try
message = reader.ReadString()
If message = "ATTACHMENT" Then
writer.Write("")
Dim num = reader.ReadInt64
Dim BR As BinaryReader
Dim FS As NetworkStream
FS = output
Dim fulname As String = reader.ReadString
BR = New BinaryReader(FS)
Dim buffer(num) As Byte
buffer = BR.ReadBytes(num)
Dim BW As BinaryWriter
Dim FSOut As FileStream
FSOut = New FileStream(fulname, FileMode.Create, FileAccess.Write)
BW = New BinaryWriter(FSOut)
BW.Write(buffer)
message = ""
BW.Close()
writer.Write("CLIENT >> ATTACHMENT RECIEVED")
End If
Catch ex As Exception
System.Environment.Exit(System.Environment.ExitCode)
End Try
Loop While message <> "SERVER >> EXIT"
クライアント側:
Do
Try
messageRecieved = reader.ReadString()
If messageRecieved = "ATTACHMENT" Then
writer.Write("")
Dim num = reader.ReadInt64
Dim BR As BinaryReader
Dim FS As NetworkStream
FS = socketStream
Dim fulname As String = reader.ReadString
BR = New BinaryReader(FS)
Dim buffer(num) As Byte
buffer = BR.ReadBytes(num)
Dim BW As BinaryWriter
Dim FSOut As FileStream
FSOut = New FileStream(fulname, FileMode.Create, FileAccess.Write)
BW = New BinaryWriter(FSOut)
BW.Write(buffer)
messageRecieved = ""
BW.Close()
writer.Write("SERVER >> ATTACHMENT RECIEVED")
End If
Catch ex As Exception
Exit Do
End Try
Loop While messageRecieved <> "CLIENT >> EXIT" And connection.Connected
于 2012-05-03T08:48:39.577 に答える