hi .
i have 2 application clinet/server the server broadcast media files to client i used tcp/ip protocol the server code is work good but i have a problem in client code i need help , ineed someone to correct the code .iwll show where the error is in the code
note: i call the class in the main form dim a as recive in the starter of the main form class to be gloable .
thanks
Code:Imports System.Net.Sockets Imports System.Windows.Forms Imports System.IO Imports System.Threading Imports System.Windows.Forms.Control Imports System.Runtime.Remoting Imports System.Runtime.Remoting.Channels Imports System.Net Public Class recieve Private reader As BinaryReader Private message As String = "" Private frmObject As frmMain ' Dim k As String = ""C:\Users\hamzah\Desktop\BVP\BVP_client\BVP.txt Private readthred As Thread Public Sub New(ByVal frmObject As frmMain) MyBase.New() Me.frmObject = frmObject readthred = New Thread(AddressOf runClinet) readthred.TrySetApartmentState(ApartmentState.STA) readthred.SetApartmentState(ApartmentState.STA) ' If readthred.TrySetApartmentState(ApartmentState.STA) Then readthred.Start() ' End If End Sub Public Sub runClinet() Dim client As TcpClient Try client = New TcpClient() client.Connect("127.0.0.1", 5234) reader = New BinaryReader(client.GetStream()) Try Dim Path As String Path = reader.ReadString frmMain.ListBox1.SelectedItem = path'Cross-thread operation not valid: Control 'ListBox1' accessed from a thread other than the thread it was created on. frmObject.Playlist.SelectedItem = frmObject.ListBox.SelectedItem 'Cross-thread operation not valid: Control 'ListBox1' accessed from a thread other than the thread it was created on. frmMain.AxWindowsMediaPlayer1.URL = Path frmObject.ListBox1.Items.Add(Path) frmObject.Playlist.Items.Add(Path) Try While True Path = reader.ReadString Select Case Path Case "1" frmObject.AxWindowsMediaPlayer1.Ctlcontrols.pause() Case "2" frmObject.AxWindowsMediaPlayer1.Ctlcontrols.play() Case "3" frmObject.AxWindowsMediaPlayer1.Ctlcontrols.stop() End Select End While Catch ex As Exception End Try Catch inputoutputException As IOException Finally End Try Try frmObject.AxWindowsMediaPlayer1.Ctlcontrols.stop() reader.Close() client.Close() Catch exx As Exception End Try Catch inputoutputException As IOException End Try End Sub End Class




Reply With Quote