My server is non-stop send out the hex code,then i want to write a small program to receive the hex data from server.
i facing a receive problem, the tcpclient only receive once only.
how can i make my program auto receive the hex data?
here is my code
please help me!
i facing a receive problem, the tcpclient only receive once only.
how can i make my program auto receive the hex data?
here is my code
VB code Code:
Imports System Imports System.ComponentModel Imports System.Net Imports System.Net.Sockets Imports System.Text Imports System.Configuration Imports vb = Microsoft.VisualBasic Public WithEvents clientSocket As New System.Net.Sockets.TcpClient() Public WithEvents myNetworkStream As System.Net.Sockets.NetworkStream Public Class frm_control_status Private ptX, ptY As Integer Dim dragging As Boolean = False Private pb As PictureBox Private comBuffer As Byte() Private Delegate Sub UpdateFormDelegate() Private UpdateFormDelegate1 As UpdateFormDelegate Dim rcvQ As New List(Of Byte) Dim rcvQlock As New Object Private Sub frm_control_status_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim ipadd, portnum As String ipadd = My.Settings.txt_ip_address portnum = My.Settings.txt_port_num If ipadd <> "" Then Try clientSocket.ReceiveBufferSize = 4096 clientSocket.Connect(ipadd, portnum) If clientSocket.Connected = True Then frm_main.lbl_server.Text = "Client Socket - Server Connected!" End If Catch ex As Exception MessageBox.Show(ex.ToString) frm_main.lbl_server.Text = "Client Socket - Disconnect!" End Try Else MsgBox("Didn't set the host IP or Port number") End If myNetworkStream = clientSocket.GetStream If myNetworkStream.CanRead = True Then Call DataReceived() End If End Sub Private Sub DataReceived() Dim n As Integer = myNetworkStream.ReadByte Dim comBuffer(n - 1) As Byte UpdateFormDelegate1 = New UpdateFormDelegate(AddressOf UpdateDisplay) myNetworkStream.Read(comBuffer, 0, n) Threading.Monitor.Enter(rcvQlock) rcvQ.AddRange(comBuffer) Threading.Monitor.Exit(rcvQlock) Me.BeginInvoke(UpdateFormDelegate1) End Sub Private Sub UpdateDisplay() do my work...... End Sub End Class
please help me!