בעיה עם Sockets ב vb.net - תכנות - HWzone פורומים
עבור לתוכן
  • צור חשבון

בעיה עם Sockets ב vb.net


nondos

Recommended Posts

שלום

כתבתי קוד ב vb.net 2005 להורדת הודעה מקבוצות דיון והצגתו ב textbox

הקוד עובד, אך רק עם הודעות קטנות בהודעות גדולות הקוד מציג רק את תחילת ההודעה.


Imports System.Xml
Imports System.Net.Sockets
Imports System.Text
Public Class Form1

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

Dim _username As String = "********"
Dim _password As String = "********"
Dim tcpClient As New TcpClient
Dim sendBytes As [Byte]()
Dim _buffer As String

tcpClient.Connect("news.giganews.com", 119)

Dim networkStream As NetworkStream = tcpClient.GetStream()

'Read the Welcome message into a byte buffer.
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))

'send username to the server
sendBytes = Encoding.ASCII.GetBytes("AUTHINFO USER " & _username & vbCrLf)
networkStream.Write(sendBytes, 0, sendBytes.Length)
ReDim bytes(tcpClient.ReceiveBufferSize)
NetworkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))

' Send Passwrod to the server
sendBytes = Encoding.ASCII.GetBytes("AUTHINFO PASS " & _password & vbCrLf)
networkStream.Write(sendBytes, 0, sendBytes.Length)
ReDim bytes(tcpClient.ReceiveBufferSize)
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))

'reset the buffer
_buffer = ""

'send command to get the message body
sendBytes = Encoding.ASCII.GetBytes("BODY <4637803c$0$32575$6c4159fb@tele2news.tweaknews.nl>" & vbCrLf)
networkStream.Write(sendBytes, 0, sendBytes.Length)

' Read the NetworkStream into a byte buffer.
ReDim bytes(tcpClient.ReceiveBufferSize)
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
_buffer = _buffer & Encoding.GetEncoding("windows-1255").GetString(bytes)
While networkStream.DataAvailable = True
ReDim bytes(tcpClient.ReceiveBufferSize)
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
_buffer = _buffer & Encoding.GetEncoding("windows-1255").GetString(bytes)
End While

TextBox1.Text = _buffer

End Sub

End Class

אני חושב שיש בעיה בשורה של ה while והתנאי שם לא מתאים והקוד יוצא מהלולאה לפני שהוא מוריד את כל ההודעה אבל לא הצלחתי ליצור תנאי אחר מתאים

תודה רבה

קישור לתוכן
שתף באתרים אחרים

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

×
  • צור חדש...