VB.NET Winsock Multithreading question.

N

Nicolas Ghesquiere

Hello

I have a problem with my current program.
The meaning of the program is to allow users to login to a server to allow
them to access the internet.
My program communicates with a MS isa server to make a rule for that IP for
the time-credits left for that user.

My problem is that so far, the program can handle everything except more
then one client, and i have done my best, but i can't find a decent solution
to get my winsock multithreaded.


i'll show you my code:


Code:

#Region " Windows Form Designer generated code "
Friend WithEvents Winsock3 As Winsock_Control.Winsock
Friend WithEvents Winsock1 As Winsock_Control.Winsock
Friend WithEvents Winsock2 As Winsock_Control.Winsock
'......
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.Winsock1 = New Winsock_Control.Winsock
Me.Winsock2 = New Winsock_Control.Winsock
Me.Winsock3 = New Winsock_Control.Winsock
'....
End Sub

#End Region

Private Sub Winsock1_ConnectionRequest(ByVal sender As
Winsock_Control.Winsock, ByVal requestID As System.Net.Sockets.Socket)
Handles Winsock1.ConnectionRequest
Winsock3.Accept(requestID)
Winsock3.Send("Connected")
txtlog.Text &= "[" & Now.ToLocalTime & "] (" &
Winsock3.RemoteHostIP() & ") Incoming Connection..." & ControlChars.CrLf
End Sub

Private Sub startlisten()
'initialised under form_load ofcourse :)
Winsock1.Listen()
txtlog.Text &= "Listening..." & ControlChars.CrLf
End Sub

Private Sub Winsock3_DataArrival(ByVal sender As
Winsock_Control.Winsock, ByVal BytesTotal As Integer) Handles
Winsock3.DataArrival
Dim s As String
Dim str As String
Dim pass As String
Dim login As String
Dim IP As String
Dim oRijndael As New Rijndael("[filtered away :] ]")
Dim substr As String = "!!_!_!!"

Winsock3.GetData(s)
IP = Winsock3.RemoteHostIP
login = s.Substring(0, s.IndexOf(substr))
pass = oRijndael.Decrypt(s.Substring(s.IndexOf(substr) + 7),
"[filtered away :] ]")
txtlog.Text &= "[" & Now.ToLocalTime & "] (" &
Winsock3.RemoteHostIP() & ") Incoming data...: LOGIN=" & login & "" &
ControlChars.CrLf
txtlog.Text &= "[" & Now.ToLocalTime & "] (" &
Winsock3.RemoteHostIP() & ") Incoming data...: PASSWORD=[encrypted]" &
s.Substring(s.IndexOf(substr) + 7) & "" & ControlChars.CrLf

'send login , pass & ip for verification
loggebruikerin(login, pass, IP)
'End If
End Sub





Any help would be very welcome, because i'm really stuck with this project
:) .
 
M

Mike Lowery

I did something similar in a program that accepts multiple simultaneous
connections from SMTP mail servers. You might want to download it and take a
look at the code and how I implemented multi-threading (it's open source):
http://spamgrinderprox.sourceforge.net/

Nicolas Ghesquiere said:
Hello

I have a problem with my current program.
The meaning of the program is to allow users to login to a server to allow
them to access the internet.
My program communicates with a MS isa server to make a rule for that IP for
the time-credits left for that user.

My problem is that so far, the program can handle everything except more then
one client, and i have done my best, but i can't find a decent solution to get
my winsock multithreaded.


i'll show you my code:


Code:

#Region " Windows Form Designer generated code "
Friend WithEvents Winsock3 As Winsock_Control.Winsock
Friend WithEvents Winsock1 As Winsock_Control.Winsock
Friend WithEvents Winsock2 As Winsock_Control.Winsock
'......
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.Winsock1 = New Winsock_Control.Winsock
Me.Winsock2 = New Winsock_Control.Winsock
Me.Winsock3 = New Winsock_Control.Winsock
'....
End Sub

#End Region

Private Sub Winsock1_ConnectionRequest(ByVal sender As
Winsock_Control.Winsock, ByVal requestID As System.Net.Sockets.Socket) Handles
Winsock1.ConnectionRequest
Winsock3.Accept(requestID)
Winsock3.Send("Connected")
txtlog.Text &= "[" & Now.ToLocalTime & "] (" & Winsock3.RemoteHostIP()
& ") Incoming Connection..." & ControlChars.CrLf
End Sub

Private Sub startlisten()
'initialised under form_load ofcourse :)
Winsock1.Listen()
txtlog.Text &= "Listening..." & ControlChars.CrLf
End Sub

Private Sub Winsock3_DataArrival(ByVal sender As Winsock_Control.Winsock,
ByVal BytesTotal As Integer) Handles Winsock3.DataArrival
Dim s As String
Dim str As String
Dim pass As String
Dim login As String
Dim IP As String
Dim oRijndael As New Rijndael("[filtered away :] ]")
Dim substr As String = "!!_!_!!"

Winsock3.GetData(s)
IP = Winsock3.RemoteHostIP
login = s.Substring(0, s.IndexOf(substr))
pass = oRijndael.Decrypt(s.Substring(s.IndexOf(substr) + 7), "[filtered
away :] ]")
txtlog.Text &= "[" & Now.ToLocalTime & "] (" & Winsock3.RemoteHostIP()
& ") Incoming data...: LOGIN=" & login & "" & ControlChars.CrLf
txtlog.Text &= "[" & Now.ToLocalTime & "] (" & Winsock3.RemoteHostIP()
& ") Incoming data...: PASSWORD=[encrypted]" & s.Substring(s.IndexOf(substr) +
7) & "" & ControlChars.CrLf

'send login , pass & ip for verification
loggebruikerin(login, pass, IP)
'End If
End Sub





Any help would be very welcome, because i'm really stuck with this project :)
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top