By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,262 Members | 2,664 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,262 IT Pros & Developers. It's quick & easy.

VB.NET Winsock Multithreading question.

P: n/a
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
:) .
Jul 27 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <th*******@skynet.bewrote in message
news:44**********************@news.skynet.be...
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 :)
.

Jul 27 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.