В момент открытия формы отображается ответ от сервера "+OK"
Однако на посыл серверу любой команды тот молчит как рыба.
Ниже привожу код. Если есть большие ляпы, то не смейтесь, а подскажите в чем беда, ибо с сокетами еще не работал.
- Код: Выделить всё
Public Class Form1
Inherits System.Windows.Forms.Form
Const READ_BUFFER_SIZE As Integer = 255
Const PORT_NUM As Integer = 110
Private client As TcpClient
Private readBuffer(READ_BUFFER_SIZE) As Byte
' Действия при открытии формы
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
client = New TcpClient("pop3.mail.ru", PORT_NUM)
client.GetStream.BeginRead(readBuffer, 0, READ_BUFFER_SIZE, AddressOf DoRead, Nothing)
Me.Show()
Catch Ex As Exception
MsgBox("Server is not active. Please start server and try again.", _
MsgBoxStyle.Exclamation, Me.Text)
Me.Dispose()
End Try
End Sub
Private Sub DoRead(ByVal ar As IAsyncResult)
Dim BytesRead As Integer
Dim strMessage As String
Try
BytesRead = client.GetStream.EndRead(ar)
If BytesRead < 1 Then
TxtDisp.AppendText("Не удалось прочитать ничего")
Exit Sub
End If
strMessage = Encoding.ASCII.GetString(readBuffer, 0, BytesRead)
TxtDisp.AppendText(strMessage)
client.GetStream.BeginRead(readBuffer, 0, READ_BUFFER_SIZE, AddressOf DoRead, Nothing)
Catch e As Exception
MsgBox("Не получилось")
End Try
End Sub
Private Sub SendData(ByVal data As String)
Dim writer As New IO.StreamWriter(client.GetStream)
writer.Write(data)
writer.Flush()
End Sub
Private Sub Send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Send.Click
SendData(TxtSay.Text)
End Sub
End Class