G
Guest
Hi, ive been working at this for a week and cant seem to get it. I want to
get a stream from an Image file so i can send it in a socket. Every attempt
i get an error saying "Buffer can not be null"....here the code, any help
would be awsome, thanks
Private Sub btnsendfile_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnsendfile.Click
Try
With Me.OpenFileDialog1
'' .Filter = "JPEG (*.jpeg)|*.jpeg"
.FilterIndex = 0
.Multiselect = False
If .ShowDialog = DialogResult.OK And .FileName <> Nothing Then
IO.File.OpenRead(.FileName)
Dim fs As New IO.FileStream(.FileName, IO.FileMode.Open,
IO.FileAccess.Read)
Dim sr As New IO.StreamReader(fs)
Dim bf As New IO.BufferedStream(fs)
Dim line As String
Dim bytes As Char()
Dim sendbytes As Byte()
If conntype Then
Dim tempsend As Byte() = ASCII.GetBytes("[Image]")
ClientSocket.BeginSend(tempsend, 0, tempsend.Length,
SocketFlags.None, AddressOf ReceiveCallBack, Nothing)
''Heres a way i tried using a streamreader
'While sr.Peek > -1
' sr.ReadBlock(bytes, 0, 1400)
' bytes.CopyTo(sendbytes, 0)
' ClientSocket.BeginSend(sendbytes, 0,
sendbytes.Length, SocketFlags.None, AddressOf ReceiveCallBack, Nothing)
'End While
''Heres how i tried it using a binary reader
'While bf.Read(sendbytes, 0, 1400) <> -1
' ClientSocket.BeginSend(sendbytes, 0,
sendbytes.Length, SocketFlags.None, AddressOf ReceiveCallBack, Nothing)
'End While
Else
Dim tempsend As Byte() = ASCII.GetBytes("[Image]")
ConnectedListen.BeginSend(tempsend, 0,
tempsend.Length, SocketFlags.None, AddressOf ListenReceiveCallBack, Nothing)
While sr.Peek > -1
sr.ReadBlock(bytes, 0, 1400)
bytes.CopyTo(sendbytes, 0)
ConnectedListen.BeginSend(sendbytes, 0,
sendbytes.Length, SocketFlags.None, AddressOf ListenReceiveCallBack, Nothing)
End While
End If
If sr.Peek <= -1 Then
If conntype Then
Dim tempsend As Byte() =
ASCII.GetBytes("[/Image]")
ClientSocket.BeginSend(tempsend, 0,
tempsend.Length, SocketFlags.None, AddressOf ReceiveCallBack, Nothing)
Else
Dim tempsend As Byte() =
ASCII.GetBytes("[/Image]")
ConnectedListen.BeginSend(tempsend, 0,
tempsend.Length, SocketFlags.None, AddressOf ListenReceiveCallBack, Nothing)
End If
End If
End If
End With
Catch ex As Exception
Me.rtbinfo.Text += ex.Message & vbNewLine
End Try
End Sub
Conntype is a boolean value on if the user connected to someone else, or
someone else connected to the user, so i know which socket to send to
get a stream from an Image file so i can send it in a socket. Every attempt
i get an error saying "Buffer can not be null"....here the code, any help
would be awsome, thanks
Private Sub btnsendfile_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnsendfile.Click
Try
With Me.OpenFileDialog1
'' .Filter = "JPEG (*.jpeg)|*.jpeg"
.FilterIndex = 0
.Multiselect = False
If .ShowDialog = DialogResult.OK And .FileName <> Nothing Then
IO.File.OpenRead(.FileName)
Dim fs As New IO.FileStream(.FileName, IO.FileMode.Open,
IO.FileAccess.Read)
Dim sr As New IO.StreamReader(fs)
Dim bf As New IO.BufferedStream(fs)
Dim line As String
Dim bytes As Char()
Dim sendbytes As Byte()
If conntype Then
Dim tempsend As Byte() = ASCII.GetBytes("[Image]")
ClientSocket.BeginSend(tempsend, 0, tempsend.Length,
SocketFlags.None, AddressOf ReceiveCallBack, Nothing)
''Heres a way i tried using a streamreader
'While sr.Peek > -1
' sr.ReadBlock(bytes, 0, 1400)
' bytes.CopyTo(sendbytes, 0)
' ClientSocket.BeginSend(sendbytes, 0,
sendbytes.Length, SocketFlags.None, AddressOf ReceiveCallBack, Nothing)
'End While
''Heres how i tried it using a binary reader
'While bf.Read(sendbytes, 0, 1400) <> -1
' ClientSocket.BeginSend(sendbytes, 0,
sendbytes.Length, SocketFlags.None, AddressOf ReceiveCallBack, Nothing)
'End While
Else
Dim tempsend As Byte() = ASCII.GetBytes("[Image]")
ConnectedListen.BeginSend(tempsend, 0,
tempsend.Length, SocketFlags.None, AddressOf ListenReceiveCallBack, Nothing)
While sr.Peek > -1
sr.ReadBlock(bytes, 0, 1400)
bytes.CopyTo(sendbytes, 0)
ConnectedListen.BeginSend(sendbytes, 0,
sendbytes.Length, SocketFlags.None, AddressOf ListenReceiveCallBack, Nothing)
End While
End If
If sr.Peek <= -1 Then
If conntype Then
Dim tempsend As Byte() =
ASCII.GetBytes("[/Image]")
ClientSocket.BeginSend(tempsend, 0,
tempsend.Length, SocketFlags.None, AddressOf ReceiveCallBack, Nothing)
Else
Dim tempsend As Byte() =
ASCII.GetBytes("[/Image]")
ConnectedListen.BeginSend(tempsend, 0,
tempsend.Length, SocketFlags.None, AddressOf ListenReceiveCallBack, Nothing)
End If
End If
End If
End With
Catch ex As Exception
Me.rtbinfo.Text += ex.Message & vbNewLine
End Try
End Sub
Conntype is a boolean value on if the user connected to someone else, or
someone else connected to the user, so i know which socket to send to