garfield 0 Report post Posted September 25, 2008 Saya kena buat assgmnt guna multicast and socket network..Cari kat internet..kebanyakkan dia bagi coding tanpa ade instruction macam mana nak guna..Kalu saya copy & paste coding dr internet..keluar banyak error and saya memang tak faham nak betulkanTolonglah bagi coding and instruction simple untuk saya lebih faham..kat sini saya paste link coding yang saya jumpa tanpa instruction dan tak faham macam mana nak start..please....http://www.java2s.com/Tutorial/VB/0400__So...dportnumber.htm Quote Share this post Link to post Share on other sites
garfield 0 Report post Posted September 25, 2008 Saya dah dapat buat coding multicast petang tadi...saya dapat buat dalam console application dan tak ada sebarang masalah...Bila saya tukar coding tu dalam window application guna form..multicast itu jadi tapi client just dapat terima message just one.Kalu nak hantar word seterusnya kena stop and run semula...Nanti saya paste kan coding client yang bermasalah itu dalam ni... Quote Share this post Link to post Share on other sites
garfield 0 Report post Posted September 26, 2008 Saya dh dpt selesaikan masalah-masalah tu..so saya paste coding untuk rujukan...kalu nak buat or terpaksa kena buat ambikla coding ni try..ni coding tuk serverImports System.Net.Sockets Imports System.Text Imports System.IO Imports System.Net Imports System.Threading Public Class Form1 Dim GroupEP As IPEndPoint Dim SendUdp As New UdpClient Dim GroupIP As IPAddress Dim bteSendData() As Byte Dim ListenUdp As New UdpClient Dim bteReceiveData() As Byte Dim strReceiveData As String Public Shared Sub Main() Dim GroupEP As IPEndPoint Dim SendUdp As New UdpClient Dim GroupIP As IPAddress GroupIP = IPAddress.Parse("225.0.0.7") GroupEP = New IPEndPoint(GroupIP, 1000) 'SendUdp.JoinMulticastGroup(GroupIP, 12) 'Dim bteSendDate() As Byte Try ' bteSendDate = Encoding.Unicode.GetBytes("yu") 'SendUdp.Send(bteSendDate, bteSendDate.Length, GroupEP) Catch ex As Exception Console.WriteLine(ex.Message) End Try End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click GroupIP = IPAddress.Parse("225.0.0.7") GroupEP = New IPEndPoint(GroupIP, 1000) Try bteSendData = Encoding.Unicode.GetBytes(TextBox1.Text) SendUdp.Send(bteSendData, bteSendData.Length, GroupEP) Catch ex As Exception End Try TextBox1.Text = "" Label1.Text = " Message successfully send" End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click End End Sub Private Shared Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'GroupIP = IPAddress.Parse("225.0.0.7") 'GroupEP = New IPEndPoint(GroupIP, 1000) 'ListenUdp.JoinMulticastGroup(GroupIP) 'bteReceiveData = ListenUdp.Receive(GroupEP) 'strReceiveData = Encoding.Unicode.GetString(bteReceiveData) 'TextBox1.Text = strReceiveData End Sub End Class ni pulak untuk client Imports System.Net.Sockets Imports System.Text Imports System.IO Imports System.Net Imports System.Threading Public Class Form1 Shared GroupIP As IPAddress Shared GroupEP As IPEndPoint Shared ListenUdp As UdpClient Dim bteReceiveData() As Byte Dim strReceiveData As String Dim bteSendData() As Byte Dim sendUdp As New UdpClient Dim ListenThread As New Thread(AddressOf BeginListen) Private Delegate Sub Yes(ByVal MSG As String) Public Shared Sub Main() End Sub Private Sub BeginListen() Dim bteReceiveData() As Byte Dim strReceiveData As String 'GroupIP = IPAddress.Parse("225.0.0.7") 'GroupEP = New IPEndPoint(GroupIP, 12345) 'ListenUdp = New UdpClient(1000) 'ListenUdp.JoinMulticastGroup(GroupIP) 'While True ' bteReceiveData = ListenUdp.Receive(GroupEP) ' strReceiveData = Encoding.Unicode.GetString(bteReceiveData) ' TextBox1.Text = strReceiveData Dim port As Integer = 12345 GroupIP = IPAddress.Parse("225.0.0.7") GroupEP = New IPEndPoint(GroupIP, port) Dim ListenUdp As New UdpClient(port) ListenUdp.JoinMulticastGroup(GroupIP) 'End While While True bteReceiveData = ListenUdp.Receive(GroupEP) strReceiveData = Encoding.Unicode.GetString(bteReceiveData) Dim ABC As Object() = {strReceiveData} Me.Invoke(New Yes(AddressOf getmsg), ABC) 'TextBox1.Text = strReceiveData End While End Sub Private Sub getmsg(ByVal MSN As String) ListBox1.Items.Add(MSN) End Sub 'Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' Dim sendUdp As New UdpClient ' GroupIP = IPAddress.Parse("225.0.0.7") ' GroupEP = New IPEndPoint(GroupIP, 1000) ' bteReceiveData = ListenUdp.Receive(GroupEP) ' strReceiveData = Encoding.Unicode.GetString(bteReceiveData) ' TextBox1.Text = strReceiveData 'End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ListenThread.Start() 'GroupIP = IPAddress.Parse("225.0.0.7") 'GroupEP = New IPEndPoint(GroupIP, 1000) 'ListenUdp = New UdpClient(1000) 'ListenUdp.JoinMulticastGroup(GroupIP) ''While True 'bteReceiveData = ListenUdp.Receive(GroupEP) 'strReceiveData = Encoding.Unicode.GetString(bteReceiveData) 'TextBox1.Text = strReceiveData ''End While End Sub 'Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' GroupIP = IPAddress.Parse("225.0.0.7") ' GroupEP = New IPEndPoint(GroupIP, 1000) ' bteSendData = Encoding.Unicode.GetBytes(TextBox1.Text) ' sendUdp.Send(bteSendData, bteSendData.Length, GroupEP) 'End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click SaveFileDialog1.Filter = "Text files (*.txt)|*.txt" SaveFileDialog1.ShowDialog() If SaveFileDialog1.FileName <> "" Then FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output) PrintLine(1, ListBox1.Text) 'copy text to disk FileClose(1) End If ListBox1.Text = "" End Sub End Classtryla..best bila dapat run dengan smooth Quote Share this post Link to post Share on other sites