troubleshooting Question

Async Multi-threaded TCP Server/Client Packet Monitor Program (A Tough Challenge)

Avatar of ITKnightMare
ITKnightMare asked on
Visual Basic.NET
4 Comments1 Solution1545 ViewsLast Modified:
Hi, I am new to .NET in general, I have written this program in VB6 fine, but since it's not multithreaded it's lame, and slow.

I am trying to write it in VB.NET NEED HELP DOING THIS O_o

Please don't just post a link and say, "Figure it out a-hole!"  I think I need to revise my whole idea to achieve this in multithreading
but this would be my first VB.NET application.

Here's a drawing of what I am trying to write.

# TAKE A LOOK HERE PLEASE #
#
#         http://img171.imageshack.us/img171/6493/achievementkz7.png
#
# TAKE A LOOK HERE PLEASE #


And here is the program in VB6


'Create a WinSock object with Index 0 so it's an array and call it, "client"

'Create another WinSock object with Index 0 and call this one, "server"

'Create one more WinSock object and call is "listener"

'______________________________________________

Sub AddNewClient()

Load client(client.UBound + 1)

Load server(server.UBound + 1)

End Sub

Private Sub client_Close(Index As Integer)

server(Index).Close

client(Index).Close

End Sub

Private Sub client_DataArrival(Index As Integer, ByVal bytestotal As Long)

Dim clientdata As String


client(Index).GetData clientdata

'Monitor the packet as clientData

server(Index).SendData clientdata


End Sub


Private Sub client_Error(Index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)

client(Index).Close

server(Index).Close

End Sub


Private Sub Form_Load()
listener.Listen
End Sub

Private Sub Form_Unload(Cancel As Integer)
listener.Close
End Sub

Private Sub listener_ConnectionRequest(ByVal requestID As Long)

If server.Count = 1 Then
AddNewClient
End If

For i = 1 To server.UBound

If server(i).State = sckClosed And client(i).State = sckClosed Then
AcceptHost i, requestID, listener.RemoteHostIP
Exit For
End If

If i = server.UBound Then
AddNewClient
AcceptHost server.UBound, requestID, listener.RemoteHostIP
End If
Next i

End Sub

Sub AcceptHost(idx, rID, rhostip)

server(idx).RemoteHost =  SERVER IP
server(idx).RemotePort = SERVER PORT
server(idx).Connect


client(idx).Accept rID
End Sub

Private Sub server_Close(Index As Integer)

client(Index).Close
server(Index).Close

End Sub

Private Sub server_DataArrival(Index As Integer, ByVal bytestotal As Long)
Dim serverdata As String

server(Index).GetData serverdata

'Monitor the packet as serverData

client(Index).SendData serverdata

End Sub


Private Sub server_Error(Index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)

client(Index).Close
server(Index).Close

End Sub
ASKER CERTIFIED SOLUTION
DjDezmond

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros