| 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: Server Tool Has Me Baffled! |
| howiegoo From: Marianna, FL USA Posts: 15 Member Since: 01/09/04 |
posted January 9, 2004 2:07 PM I'm really not understanding how the server tool works. Here is what I need to do: Create a server app that listens on a port for new connections and adds their ip and port information into a listview when they connect. I've accomplished this with the following code: Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Server1.Listen(5555) End Sub Private Sub Server1_Connection(ByVal sender As Object, ByVal e As Dart.PowerTCP.Sockets.ConnectionEventArgs) Handles Server1.Connection Try Dim IPandPort As String = e.Tcp.RemoteEndPoint.ToString Dim Int As Integer = IPandPort.LastIndexOf(":") Dim CIP As String = Trim(IPandPort.Substring(0, Int)) Dim CPort As String = Trim(IPandPort.Substring(Int + 1, IPandPort.Length - (Int + 1))) Dim ITMX As New ListViewItem() ITMX = LSV1.Items.Add(CIP) ITMX.SubItems.Add(CPort) Catch ex As Exception MsgBox(ex.Message) End Try End Sub How do I detect if a connection to a client severed? How do I work with a specific connection in the list? For example how could I send some data to the third connection in the list but not the others? I know that e.tcp holds the connection's information inside the Server1_Connection event but how do I work with connections outside of this event? Please help! |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted January 9, 2004 2:43 PM Have you taken a look at the sample apps? Please do so and see if you still have questions. |
| howiegoo From: Marianna, FL USA Posts: 15 Member Since: 01/09/04 |
posted January 9, 2004 2:55 PM Yes I've looked at them but can't understand how to work with the connections outside of the Server1_Connection event. I've tried feeding the server1.connections arraylist into another listview but they are all the same and contain no information about the connections themselves. Basically I'm just trying to get at the connections after they are made and don't seem to be able to wrap my brain around how to do it... |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted January 9, 2004 3:09 PM In your code, the connection is going to go away as soon as it's connected. The samples all do a blocking receive forever until the other side closes. This means that the entire life of the connection is inside the connection event. See the connection class for each sample to see how this is accomplished. |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted January 9, 2004 3:17 PM I need to correct what I just said. The connection will not "go away". You just won't have a reference to it so nothing will happen. |
| howiegoo From: Marianna, FL USA Posts: 15 Member Since: 01/09/04 |
posted January 9, 2004 3:37 PM Ah I see. The samples appear to be written for a single connection. I need to make several connections from clients to the server and I need to be able to differentiate between and manipulate them individually. For example: Say I need to get connection 15's IP information or send it some data. How do I tell it appart from all the others and how do I reference it? I have it in the listview but that doesn't actually point to anything. Is there a way to tie the entry in the listview to the connection and get at it from there? |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted January 9, 2004 3:48 PM That is an incorrect assumption. Did you try connecting more than once to the sample apps? Try it and you will see that it works. The server component is multi-threaded, so each connection runs in it's own thread. That's why we do all that stuff with delegates and BeginInvoke when communicating with the textbox on the main form, to prevent the threads from trying to update the textbox at the same time. To do what you want, create the ListItem, then assign the connection to the Tag property of the Item. |
| howiegoo From: Marianna, FL USA Posts: 15 Member Since: 01/09/04 |
posted January 12, 2004 11:39 AM AH! I finally understand! Sorry for the confusion. |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted January 12, 2004 11:40 AM No problem! |
| Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums |
This site is powered by
PowerTCP WebServer for ActiveX
|