| Dart Home | PowerTCP Sockets for .NET | Custom Development | Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums |
| Author | Forum: PowerTCP Sockets for .NET (Secure and Standard) Topic: UDP to SQL |
| brianza brianza@compunet.com.mt From: Mosta, Malta Posts: 5 Member Since: 07/26/06 |
posted July 26, 2006 11:43 AM I would like to open UDP socket 6080 on my machine using VB .Net 2003 and store a string which is 20 Characters long in a field called Track in my sql database. My problem is that I am receiving data all the time. How can I control the socket to make it receive this data in batches of 20 characters? Alternatively can I keep the socket open and pick what I need from there? If so how thanks Brian |
| Amit From: Rome, NY USA Posts: 315 Member Since: 03/15/06 |
posted July 26, 2006 3:52 PM Hello, I have read the query and it is my understanding that you are looking to store the received data in a String. If this is the said scenario, then I would appreciate if you could let us know whether you are using a trial version of the product, and if not, which licensed version of the product do you have running? Have a nice day ahead. Best Regards, Amit |
| brianza brianza@compunet.com.mt From: Mosta, Malta Posts: 5 Member Since: 07/26/06 |
posted July 26, 2006 3:56 PM Dear Amit, thanks foir your reply. I am using the trail version of your product in order to verify whether it fits my needs. I would like to have UDP always open and be able to store the strings I receive |
| Amit From: Rome, NY USA Posts: 315 Member Since: 03/15/06 |
posted July 26, 2006 4:55 PM Hello, Regarding the query, I would appreciate if you could try the following code snippet to achieve the desired behavior: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'In this example, data of a certain length is received. ' For Simplicity this data is sent to an echo server, so the data received can be easily controlled. 'To specify local port 6080 use the Open method. This method allocates a socket for sending and receiving datagrams. Udp1.Open(6080) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'Text of TextBox1 will be converted to a String(strSend) Dim strSend As String = TextBox1.Text 'Send a datagram to the Server Udp1.Send(strSend, "ServerAddress", "ServerPort") 'Create an instance of the DataGram 'You need to add a reference of Dart.PowerTCP.Sockets.dll through the ‘add reference window 'After this add the following statement to the general declarations 'Imports Dart.PowerTCP.Sockets Dim da As Datagram 'Receive the echoed data da = Udp1.Receive(strSend.Length) 'Assign the received data to the Second textbox TextBox2.Text = da.ToString() End Sub Alternatively, you may also use BeginReceive (asynchronous) method to achieve the desired scenario. The following code snippet has worked fine at my end: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' In this example BeginReceive method is used. 'To specify local port 6080 use the Open method. This method allocates a socket for sending and receiving datagrams. Udp1.Open(6080) Dim bytBuffer(Udp1.BufferSize) As Byte 'This method begins the asynchronous use.When this method is completed then the EndReceive event will be raised. Udp1.BeginReceive(bytBuffer) End Sub Private Sub Udp1_EndReceive(ByVal sender As Object, ByVal e As Dart.PowerTCP.Sockets.DatagramEventArgs) Handles Udp1.EndReceive 'Echo the data back into the event. 'RemoteEndPoint can be address or port of the client Udp1.Send(e.Datagram.ToString(), e.Datagram.RemoteEndPoint) 'This will start receiving the bytes Dim bytBuffer(Udp1.BufferSize) As Byte Udp1.BeginReceive(bytBuffer) End Sub You may also use a byte Array so that the data is received in batches of 20 characters. You may also take a look at the samples located at the following location: C:\Program Files\PowerTCP\Sockets for .NET\Samples I hope this will be of help. In case of further assistance/ clarifications, please feel free to write back and I would be glad to assist you. Have a nice day ahead. Best Regards, Amit |
| Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums |
This site is powered by
PowerTCP WebServer for ActiveX
|