 |
|
 |
hi,
my concern is the same with sivaramireddy, how can i chck the successful of the messages been sent.
thank you very much.
regards,
dunk
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
 | Threads  Member 4619895 | 17:09 17 Jun '09 |
|
 |
Thanks Kumudu for good coding and explaination,
I am always thining about multithreading in similar cases, Is there any real danger that while the reciever thread is updating the bytes array, the main thread will be using this data (i.e. corrupted)?
To be more clear: The first CPU is reieveing a byte array, while it's "filling" this array, the second CPU uses this data ... What do you think about that?
Thanks in advance
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
The code is not a complete explanation, can I please post my complete code with comments?? Otherwise very useful! 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
hello sir
i saw your coding i try it but i have some error is came this is the error
Cross-thread operation not valid: Control 'TextBox1' accessed from a thread other than the thread it was created on.
can you help me please
Coding :
Public Sub ReceiveMessages() Dim program As New Process() Dim s As String Dim receiveBytes As [Byte]() = receivingUdpClient.Receive(RemoteIpEndPoint) ' MsgBox(RemoteIpEndPoint.Port.ToString) Dim BitDet As BitArray BitDet = New BitArray(receiveBytes) Dim strReturnData As String = System.Text.Encoding.Unicode.GetString(receiveBytes) 'MsgBox(strReturnData) s = Encoding.ASCII.GetString(receiveBytes) TextBox1.Text += TextBox1.Text + Encoding.ASCII.GetString(receiveBytes) MsgBox(s.ToCharArray) NewInitialize() If s = "NOTEPAD" Then program.StartInfo.FileName = "Notepad.exe" program.StartInfo.Arguments = " " program.Start()
End If
End Sub
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
 |
you are accessing a object from another thread other than the object was made on
here the txtbox was made on the main thread but you are running this code on another thread using threading, i dont know VB but i know C# in C# we use
this.Invoke((MethodInvoker)delegate { });
For Example: this.Invoke((MethodInvoker)delegate { lblProgress.Text = "Preparing to Start Downloading Update..."; });
use any VB-C#/C#-VB code converter to convert this line.. google for converter though i think (maybe) this will NOT work if you are doing multi threading
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
i have UDP send program that working well in LAN.But when i try it on the internet,i try to send msg to dynamic ip address(behind router) it seems the destination pc cannot receive any message from the udp sender.
please help me
hey
|
| Sign In·View Thread·PermaLink | 1.80/5 |
|
|
|
 |
|
 |
First, let me say thank you for taking the time to post this example. I've been trying to learn UDP messaging and have had 0 luck finding any good examples.
I think you may have an error in the code though. On this line you encode the string you are sending to the listening host in ASCII: bytCommand = Encoding.ASCII.GetBytes(txtMessage.Text)
Later in the ReceiveMessages routine you decode the byte array using Unicode, which gives a different result: Dim strReturnData As String = System.Text.Encoding.Unicode.GetString(receiveBytes)
Of course, this is a moot point if you're working with purely binary data later on (ie an image or executable, etc).
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
I am trying to use the project from the article http://www.codeproject.com/KB/IP/UDP_Send_Receive.aspx I was hoping to find an application that did both send and receive in 1 package I am able to receive the data that I wanted i had to change ASCII to Default due to the data is not displayable characters that would make any sense For now so I could see the received bytes I placed them in a list box a good example of what I see in the list box is 34 0 0 0 35 0 0 0 152 135 157 0
What I want to to is reply back to the same client with that information and 10 more bytes of information
The part I am stumpted on is the reply from the port being listened to to the IP & port being sent from
modified on Saturday, December 08, 2007 4:42:43 PM
|
| Sign In·View Thread·PermaLink | 2.20/5 |
|
|
|
 |
|
|
 |
 | hi  rakeshdasgupta | 1:51 10 May '07 |
|
 |
hi i m making a lan messenger using the built in net send command in windows i wanted to ask how can i send files on the lan throught it. or wud it be better to use tcp or udp protocol instead plz guide thnks
rdg
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
Is there anyway to make this into an instant messenger using the ip address. if so is how would you go about saving the address to a "user name" type deal
|
| Sign In·View Thread·PermaLink | 1.33/5 |
|
|
|
 |
|
 |
I am sending the image data over the UDP from one PC to another. I want to see that raw data as well as the full image. But i don't know how to do this.
Can anyone help??
Vipin
|
| Sign In·View Thread·PermaLink | 1.25/5 |
|
|
|
 |
|
 |
i made a somewhat easy to use class for the udp protocall using this let me know what you think. it needs comments though. my spelling is not good and i am to sleepy to spell check...
you have to give Kumudu Gunasekara and me (william k.) credit if you want to use this class -------------------------------------------------------------------------------------------
Class UdpProto Public Structure Messageing 'use this structure to get the received messages Dim IpAddress As Net.IPAddress Dim Message As [Byte]() End Structure
Public PortNumber As Integer = 1101 'any port to receive on
Private Received As New ListBox
Private udpClient As New Net.Sockets.UdpClient Private receivingUdpClient As Net.Sockets.UdpClient Private RemoteIpEndPoint As New _ System.Net.IPEndPoint(System.Net.IPAddress.Any, 0) Private ThreadReceive As System.Threading.Thread
Private GLOIP As Net.IPAddress Private GLOINTPORT As Integer Private bytCommand As Byte() = New Byte() {}
Public Sub StartListener()
Try receivingUdpClient = New System.Net.Sockets.UdpClient(PortNumber) Catch ex As Exception End Try
Try If ThreadReceive.IsAlive = True Then Exit Sub Catch ex As Exception End Try ThreadReceive = New System.Threading.Thread(AddressOf ReceiveMessages) ThreadReceive.Start() End Sub
Public Sub StopListener() Try If ThreadReceive.IsAlive = True Then receivingUdpClient.Close() ThreadReceive.Abort() End If Catch ex As Exception
End Try End Sub
Public Sub SendMessage(ByVal ToIP As Net.IPAddress, ByVal Port As Integer, ByVal Message As [Byte]()) Dim pret As Integer GLOIP = ToIP GLOINTPORT = Port udpClient.Connect(GLOIP, GLOINTPORT) bytCommand = Message pret = udpClient.Send(bytCommand, bytCommand.Length)
End Sub
Public Function GetMessage() As Messageing Dim b As Byte() = {0} Dim y As Messageing y.IpAddress = Net.IPAddress.Parse("0.0.0.0") y.Message = b GetMessage = y If Received.Items.Count > 0 Then GetMessage = Received.Items.Item(0) Received.Items.RemoveAt(0) End If End Function
Private Sub ReceiveMessages() Dim receiveBytes As [Byte]() = receivingUdpClient.Receive(RemoteIpEndPoint) Dim newMess As Messageing newMess.Message = receiveBytes newMess.IpAddress = RemoteIpEndPoint.Address TheReceiver(newMess) ReceiveMessages() End Sub
Private Sub TheReceiver(ByVal Mess As Messageing) Received.Items.Add(Mess) End Sub
End Class
-- modified at 4:49 Monday 9th October, 2006
|
| Sign In·View Thread·PermaLink | 2.50/5 |
|
|
|
 |
|
 |
This is a very good example, thanks for sharing. I made a TFTP server program with reference to some of the concept mentioned. But now here comes the problem, hope somebody can provide a simple way to help...
In the UDP receiving thread I made a 'while true' loop to make this thread always on for new connections. Meanwhile there must be a button in the main thread (UI) that user can click to terminate the whole program (main thread event to close the UDP thread safely). I found a references on MSDN by building an intermediate controller(agent) interface between main and UDP. But, this is too complicated for a simple program.
Almost every simple example I can find on the net refers to closing a one-shot (do this and thread.sleep(5000) to wait for main thread to close it) thread instead of a user terminate-able always on thread.
Can somebody help with this? I belive many amature VB6 users will have similar questions as I do.
Thanks...
-- modified at 11:39 Wednesday 2nd August, 2006
|
| Sign In·View Thread·PermaLink | 1.80/5 |
|
|
|
 |
|
 |
Yes... I had the same issue. Posted the question on the microsoft newsgroup and got an answer.
Long story short, If you close the socket first...the thread will close. so do something like this: Example: Sub Form close()
receivingUdpClient.Close() Thread.Abort()
=== The explination i was given was this: posted on microsoft.public.dotnet.languages.vb title: Cant Stop A Thread
Actually, if your using blocking socket calls (ReceiveFrom?) then it does matter. A call to Thread.Abort is only a request, it doesn't guarentee that a thread will immediately exit. The problem with the blocking socket calls is at the low level, they are actually calling out into unmanaged code - and so the ThreadAbortException is not thrown until the call returns (look at the docs for a more detailed explanation). The way I usually handle this is simply close the socket. This causes the blocking read to return, and then you can exit the thread... By Tom Shelton
====
Hope that helps ya
Miro
|
| Sign In·View Thread·PermaLink | 1.57/5 |
|
|
|
 |
|
|
 |
|
 |
Hi..... Do you have the 2005 VC++.net UDP client / server sample code. Thanks a lot of your assistance.
Regards, Andrew email: andrew_ck_lo@hotmail.com
Andrew
|
| Sign In·View Thread·PermaLink | 1.40/5 |
|
|
|
 |
|
 |
I try to connect multipule ip same time tyr send data to all only 1 click button like mess message.
Please give any example in vb .net
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
|
 |
 | TCP/IP  NeeruVerma | 20:26 13 Mar '06 |
|
 |
Nice article for newbie's like me.
I need to know how can we achieve the same thing using TCP/IP in VB.Net itself.
Regards, Neeru
No problem is too small or too trivial if we can really do something about it.
|
| Sign In·View Thread·PermaLink | 1.44/5 |
|
|
|
 |
|
 |
Great article about the UDP sendig/receiving, but the usage of threds seems to have a small problem (at the server side). The subroutine ReceiveMessages() activates a new thread at the last statement of the subroutine. This seems to work fine, but the previous instance never ends. This causes memory consumption. You can see this if you use TaskManager and look at the memory usage of the program. When you receive several messages the memory usage of the receiving program grows up.
One solution to prevent this problem is to take the "NewInitialize()" line out and make an infinite loop inside the ReceiveMessages() routine. This infinite loop can be done for example by inserting DO statement at the beginning of the ReceiveMessages() routine and LOOP WHILE TRUE to the end of the routine. (So the infinite loop includes all the lines of the routine)
The infinite loop ends when the Button_2_Click() is called.
I made some other modifications into my application according to my needs and I didn't test these modifications in the original version, but I think they should work here also. (If they don't, please send a new message to this thread.)
-- modified at 16:46 Wednesday 22nd February, 2006
|
| Sign In·View Thread·PermaLink | 2.71/5 |
|
|
|
 |
|
 |
Excellent article. We appreciate such simple, straightforward designs.
Code works well on .net 2003, but throws exception on .net 2005. Anyone else experience this problem
|
| Sign In·View Thread·PermaLink | 2.88/5 |
|
|
|
 |
|
 |
.net 2005 does not let you update form controls from a thread other then the one that created the form. You need to call back to main thread to update all the controls. For example: Delegate Sub SetTextCallback(ByVal strText As String) Public Sub SetText(ByVal strText As String)
' InvokeRequired required compares the thread ID of the ' calling thread to the thread ID of the creating thread. ' If these threads are different, it returns true. If Me.TextBox1.InvokeRequired Then Dim d As New SetTextCallback(AddressOf SetText) Me.Invoke(d, New Object() {strText}) Else Me.TextBox1.Text = Me.TextBox1.Text & strText End If End Sub Then instead of this: TextBox1.Text = TextBox1.Text & vbCrLf & "The length of the message is " You put: SetText(vbCrLf & "The length of the message )
You would need to do the same for the txtIP control
Also, I had to change the: System.Text.Encoding.Unicode.GetString(receiveBytes) to: System.Text.Encoding.ASCII.GetString(receiveBytes)
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |