を非同期メソッドを使用して受信していません。私は小さなパケットに画像を「カット」し、もう一方の端でそれを再構成する必要があります。これまで私はサーバーとほとんどのクライアント(サーバーが画像を送信する)を作成しました。私はBeginReceiveでいくつかのテストを行い、(他のプロジェクトで)作業しました。今私はクライアント上で何も得られません(エラーはありません)。ここでは、サーバーのコードだ:ませUDPパケットは、私はUDPを使用してLAN経由で画像を送信しようとしているVB.Net
Imports System
Imports System.IO
Imports System.Net
Imports System.Threading
Imports System.Net.Sockets
Imports System.Text.Encoding
Public Class Form1
Dim publisher As New Sockets.UdpClient(0)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sendbytes() As Byte = ASCII.GetBytes(txt1.Text)
Dim img As Image, img_stream As MemoryStream, buffer As Byte()
Dim packet_size As Integer = 1500, sent_size As Long
Try
publisher.Connect("localhost", 60000)
img_stream = imgToBytes(txt1.Text)
ReDim buffer(packet_size)
While Not img_stream.Position = img_stream.Length
sent_size += img_stream.Read(buffer, 0, packet_size)
publisher.Send(buffer, buffer.Length)
End While
Catch ex As Exception
Debug.Print(ex.Message)
End Try
End Sub
Function imgToBytes(ByVal file_name As String) As MemoryStream
Dim img As Image = Image.FromFile(file_name)
Dim stream As New MemoryStream
img.Save(stream, Drawing.Imaging.ImageFormat.Jpeg)
stream.Position = 0
Return stream
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Form2.Show()
End Sub
End Class
クライアントが第二の形式である:
Imports System
Imports System.IO
Imports System.Net
Imports System.Threading
Imports System.Net.Sockets
Imports System.Text.Encoding
Public Class Form2
Dim ep As IPEndPoint = New IPEndPoint(IPAddress.Any, 0)
Dim client As New UdpClient(1000)
Public Event new_msg(ByVal msg As Byte())
Public Sub client_msg(ByVal msg As Byte())
Debug.Print("a")
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try ''don't know why I put this here
client.BeginReceive(New AsyncCallback(AddressOf receive), client)
Catch ex As Exception
Debug.Print(ex.Message)
End Try
End Sub
Sub receive(ByVal ar As IAsyncResult)
Dim buffer As Byte()
Debug.Print("b")
Try
buffer = client.EndReceive(ar, ep)
''RaiseEvent new_msg(buffer)
client.BeginReceive(New AsyncCallback(AddressOf receive), client)
Catch ex As Exception
Debug.Print(ex.Message)
End Try
End Sub
End Class
どこに問題がありますか?
あなたが強化していますブレークポイントを使用してコードを介して? –
いいえ...私は何かを得るとは思わない...どこにでもプリントを置く...何もなし –
ブレークポイント経由で、あなたのアプリケーションがコードの実行を停止する場所を得ることができます。私は今あなたのコードを試しています。あなたが受け取ったデータで何もしないことに気づくことはできませんが、本当に何が問題なのですか? –