I am using ThreadPool to call a sub in a class. The first time the
ThreadPool is called, I created a socket in the thread. I can connect a
client to the socket and send a message to the client (in ThreadMain),
but when the client send a message to me, the Sub SocketClient_OnRead
event did not get fired. How can I fix this problem ?
Thank you.
Imports SocketTools.SocketWrench.ErrorCode
Private WithEvents Socket As SocketTools.SocketWrench
Private Sub ServerForm_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
Dim nIndex As Integer
' Create an instance of the SocketWrench class which will
' function as our listening (server) socket
Socket = New SocketTools.SocketWrench
If Not Socket.IsInitialized Then
Throw New System.Exception("Unable to initialize
SocketWrench class")
End If
:
end sub
Private Sub ListenButton_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles ListenButton.Click
If Socket.IsListening Then
Socket.Disconnect()
Else
Dim strLocalAddress As String
Dim nLocalPort As Integer
strLocalAddress = LocalAddress.Text.Trim()
nLocalPort = Val(LocalPort.Text)
Socket.Blocking = False
If Not Socket.Listen(strLocalAddress, nLocalPort) Then
exit sub
end if
end sub
Private Sub Socket_OnAccept(ByVal sender As Object, ByVal e As
SocketTools.SocketWrench.AcceptEventArgs) Handles Socket.OnAccept
Dim oSession As SessionClass
oSession = New SessionClass
oSession.Handle = e.Handle
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf
oSession.ThreadMain), "CreateSocket")
end sub
Public Class SessionClass
Public WithEvents SocketClient As SocketTools.SocketWrench
Public Sub ThreadMain(ByVal data As Object)
Dim nResult As Integer
Dim Message As String
Message = CType(data, String)
If Message = "CreateSocket" Then
CreateSocket()
Else
nResult = SocketClient.Write(Message) '--> this one is send
out to cllient fine
End If
End Sub
Public Sub CreateSocket()
SocketClient = New SocketTools.SocketWrench
SocketClient.Initialize()
If Not SocketClient.Accept(Handle) Then
Exit Sub
End If
'AddHandler SocketClient.OnRead, AddressOf SocketClient_OnRead
--> even adding this does not help
End Sub
Private Sub SocketClient_OnRead(ByVal sender As Object, ByVal e As
System.EventArgs) Handles SocketClient.OnRead
Dim x As Integer
x = 1 '---> this event never gets fired
End Sub 3 2108
fniles wrote: I am using ThreadPool to call a sub in a class. The first time the ThreadPool is called, I created a socket in the thread. I can connect a client to the socket and send a message to the client (in ThreadMain), but when the client send a message to me, the Sub SocketClient_OnRead event did not get fired. How can I fix this problem ? Thank you.
Imports SocketTools.SocketWrench.ErrorCode
Private WithEvents Socket As SocketTools.SocketWrench
Private Sub ServerForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim nIndex As Integer
' Create an instance of the SocketWrench class which will ' function as our listening (server) socket Socket = New SocketTools.SocketWrench If Not Socket.IsInitialized Then Throw New System.Exception("Unable to initialize SocketWrench class") End If : end sub
Private Sub ListenButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListenButton.Click If Socket.IsListening Then Socket.Disconnect() Else Dim strLocalAddress As String Dim nLocalPort As Integer
strLocalAddress = LocalAddress.Text.Trim() nLocalPort = Val(LocalPort.Text) Socket.Blocking = False If Not Socket.Listen(strLocalAddress, nLocalPort) Then exit sub end if end sub
Private Sub Socket_OnAccept(ByVal sender As Object, ByVal e As SocketTools.SocketWrench.AcceptEventArgs) Handles Socket.OnAccept Dim oSession As SessionClass
oSession = New SessionClass oSession.Handle = e.Handle ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf oSession.ThreadMain), "CreateSocket") end sub
Public Class SessionClass Public WithEvents SocketClient As SocketTools.SocketWrench
Public Sub ThreadMain(ByVal data As Object) Dim nResult As Integer Dim Message As String
Message = CType(data, String) If Message = "CreateSocket" Then CreateSocket() Else nResult = SocketClient.Write(Message) '--> this one is send out to cllient fine End If End Sub
Public Sub CreateSocket() SocketClient = New SocketTools.SocketWrench SocketClient.Initialize()
If Not SocketClient.Accept(Handle) Then Exit Sub End If 'AddHandler SocketClient.OnRead, AddressOf SocketClient_OnRead --> even adding this does not help End Sub
Private Sub SocketClient_OnRead(ByVal sender As Object, ByVal e As System.EventArgs) Handles SocketClient.OnRead Dim x As Integer
x = 1 '---> this event never gets fired End Sub
I really don't know Catalysts stuff very well... But, I have to wonder
why you would want to use a 3rd party library for this? Does this
provide features, that can't be found in the System.Net and
System.Net.Sockets namespaces?
I'm trying to think of some questions that might unravel this a bit...
The only things right now I can think of is what version of this
control is it? Is it a .NET control or a COM control? I am vaguely
uncomfortable with the structure of your code - but I would need to do
a little research to verify...
--
Tom Shelton [MVP]
Thanks.
The reason why we chose 3rd party (it is a .NET Component) because in VB6
Microsoft Winsock control is slower than a 3rd party control.
What .NET socket component that I can use that has good performance ?
Thanks.
"Tom Shelton" <to*@mtogden.com> wrote in message
news:11**********************@f6g2000cwb.googlegro ups.com... fniles wrote: I am using ThreadPool to call a sub in a class. The first time the ThreadPool is called, I created a socket in the thread. I can connect a client to the socket and send a message to the client (in ThreadMain), but when the client send a message to me, the Sub SocketClient_OnRead event did not get fired. How can I fix this problem ? Thank you.
Imports SocketTools.SocketWrench.ErrorCode
Private WithEvents Socket As SocketTools.SocketWrench
Private Sub ServerForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim nIndex As Integer
' Create an instance of the SocketWrench class which will ' function as our listening (server) socket Socket = New SocketTools.SocketWrench If Not Socket.IsInitialized Then Throw New System.Exception("Unable to initialize SocketWrench class") End If : end sub
Private Sub ListenButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListenButton.Click If Socket.IsListening Then Socket.Disconnect() Else Dim strLocalAddress As String Dim nLocalPort As Integer
strLocalAddress = LocalAddress.Text.Trim() nLocalPort = Val(LocalPort.Text) Socket.Blocking = False If Not Socket.Listen(strLocalAddress, nLocalPort) Then exit sub end if end sub
Private Sub Socket_OnAccept(ByVal sender As Object, ByVal e As SocketTools.SocketWrench.AcceptEventArgs) Handles Socket.OnAccept Dim oSession As SessionClass
oSession = New SessionClass oSession.Handle = e.Handle ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf oSession.ThreadMain), "CreateSocket") end sub
Public Class SessionClass Public WithEvents SocketClient As SocketTools.SocketWrench
Public Sub ThreadMain(ByVal data As Object) Dim nResult As Integer Dim Message As String
Message = CType(data, String) If Message = "CreateSocket" Then CreateSocket() Else nResult = SocketClient.Write(Message) '--> this one is send out to cllient fine End If End Sub
Public Sub CreateSocket() SocketClient = New SocketTools.SocketWrench SocketClient.Initialize()
If Not SocketClient.Accept(Handle) Then Exit Sub End If 'AddHandler SocketClient.OnRead, AddressOf SocketClient_OnRead --> even adding this does not help End Sub
Private Sub SocketClient_OnRead(ByVal sender As Object, ByVal e As System.EventArgs) Handles SocketClient.OnRead Dim x As Integer
x = 1 '---> this event never gets fired End Sub
I really don't know Catalysts stuff very well... But, I have to wonder why you would want to use a 3rd party library for this? Does this provide features, that can't be found in the System.Net and System.Net.Sockets namespaces?
I'm trying to think of some questions that might unravel this a bit... The only things right now I can think of is what version of this control is it? Is it a .NET control or a COM control? I am vaguely uncomfortable with the structure of your code - but I would need to do a little research to verify...
-- Tom Shelton [MVP]
Take a look at the native system.net.socket classes. They are quick and
powerful. I was able to use these classes to replace the WinINET and
MSWinSck.OCX interfaces that I used in VB 6.
Mike Ober.
"fniles" <fn****@pfmail.com> wrote in message
news:OA**************@TK2MSFTNGP04.phx.gbl... Thanks. The reason why we chose 3rd party (it is a .NET Component) because in VB6 Microsoft Winsock control is slower than a 3rd party control. What .NET socket component that I can use that has good performance ?
Thanks.
"Tom Shelton" <to*@mtogden.com> wrote in message news:11**********************@f6g2000cwb.googlegro ups.com... fniles wrote: I am using ThreadPool to call a sub in a class. The first time the ThreadPool is called, I created a socket in the thread. I can connect a client to the socket and send a message to the client (in ThreadMain), but when the client send a message to me, the Sub SocketClient_OnRead event did not get fired. How can I fix this problem ? Thank you.
Imports SocketTools.SocketWrench.ErrorCode
Private WithEvents Socket As SocketTools.SocketWrench
Private Sub ServerForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim nIndex As Integer
' Create an instance of the SocketWrench class which will ' function as our listening (server) socket Socket = New SocketTools.SocketWrench If Not Socket.IsInitialized Then Throw New System.Exception("Unable to initialize SocketWrench class") End If : end sub
Private Sub ListenButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListenButton.Click If Socket.IsListening Then Socket.Disconnect() Else Dim strLocalAddress As String Dim nLocalPort As Integer
strLocalAddress = LocalAddress.Text.Trim() nLocalPort = Val(LocalPort.Text) Socket.Blocking = False If Not Socket.Listen(strLocalAddress, nLocalPort) Then exit sub end if end sub
Private Sub Socket_OnAccept(ByVal sender As Object, ByVal e As SocketTools.SocketWrench.AcceptEventArgs) Handles Socket.OnAccept Dim oSession As SessionClass
oSession = New SessionClass oSession.Handle = e.Handle ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf oSession.ThreadMain), "CreateSocket") end sub
Public Class SessionClass Public WithEvents SocketClient As SocketTools.SocketWrench
Public Sub ThreadMain(ByVal data As Object) Dim nResult As Integer Dim Message As String
Message = CType(data, String) If Message = "CreateSocket" Then CreateSocket() Else nResult = SocketClient.Write(Message) '--> this one is send out to cllient fine End If End Sub
Public Sub CreateSocket() SocketClient = New SocketTools.SocketWrench SocketClient.Initialize()
If Not SocketClient.Accept(Handle) Then Exit Sub End If 'AddHandler SocketClient.OnRead, AddressOf SocketClient_OnRead --> even adding this does not help End Sub
Private Sub SocketClient_OnRead(ByVal sender As Object, ByVal e As System.EventArgs) Handles SocketClient.OnRead Dim x As Integer
x = 1 '---> this event never gets fired End Sub
I really don't know Catalysts stuff very well... But, I have to wonder why you would want to use a 3rd party library for this? Does this provide features, that can't be found in the System.Net and System.Net.Sockets namespaces?
I'm trying to think of some questions that might unravel this a bit... The only things right now I can think of is what version of this control is it? Is it a .NET control or a COM control? I am vaguely uncomfortable with the structure of your code - but I would need to do a little research to verify...
-- Tom Shelton [MVP]
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Phil Jenson |
last post by:
I am try to evaluate the most efficient method of handling thousands of
simultaneous TCP connects each of which remain connected to the server for
hours and pass a small amount of data usually once...
|
by: Rekkie |
last post by:
Hi,
I am trying to implement a ping client that is multithreading. The
approach I have used is to create a ping class which I instantiate
from the main thread and which contains a method...
|
by: Chris Tanger |
last post by:
Context:
C#
System.Net.Sockets
Socket created with constructor prarmeters Internetwork, Stream and TCP
everything else is left at the default parameters and options except linger
may be changed...
|
by: Alexander Muylaert |
last post by:
Hi
I their a way I can interupt socket.Receive.
I want my multi-threader server to be able to handle requests as wel as
Broadcast messages. This broadcasting is done when the socket is not...
|
by: Richard |
last post by:
Hi,
I'm suffering a socket race condition - I think. The code works fine at
full speed on a single CPU machine. However when I run full speed on a 2
Zeon machine the socket drops data on an...
|
by: mscirri |
last post by:
The code below is what I am using to asynchronously get data from a
PocketPC device. The data comes in fine in blocks of 1024 bytes but
even when I send no data from the PocketPC constant blocks of...
|
by: Laura T. |
last post by:
Hi,
I've this kind a program, using sockets to communicate with the clients. One
of the clients can be a web browser (like IE).
When using IE as a client, the transmission blocks completely, and...
|
by: Roodie |
last post by:
Hello,
I have a quite specific problem, and after half a day spent with
Google, still no solid answer.
The task:
I have to write a C# class Library ( DLL ) to handle TCP socket...
|
by: Bruce |
last post by:
Hello
I am building a C# app that creates anywhere from 10 to 100
connections to a specified server and sends 1000s of TCP requests and
processes the responses. (it is a stress tool)
I planned...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |