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_On Read
event did not get fired. How can I fix this problem ?
Thank you.
Imports SocketTools.Soc ketWrench.Error Code
Private WithEvents Socket As SocketTools.Soc ketWrench
Private Sub ServerForm_Load (ByVal sender As System.Object, ByVal e
As System.EventArg s) 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.Soc ketWrench
If Not Socket.IsInitia lized Then
Throw New System.Exceptio n("Unable to initialize
SocketWrench class")
End If
:
end sub
Private Sub ListenButton_Cl ick(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles ListenButton.Cl ick
If Socket.IsListen ing Then
Socket.Disconne ct()
Else
Dim strLocalAddress As String
Dim nLocalPort As Integer
strLocalAddress = LocalAddress.Te xt.Trim()
nLocalPort = Val(LocalPort.T ext)
Socket.Blocking = False
If Not Socket.Listen(s trLocalAddress, nLocalPort) Then
exit sub
end if
end sub
Private Sub Socket_OnAccept (ByVal sender As Object, ByVal e As
SocketTools.Soc ketWrench.Accep tEventArgs) Handles Socket.OnAccept
Dim oSession As SessionClass
oSession = New SessionClass
oSession.Handle = e.Handle
ThreadPool.Queu eUserWorkItem(N ew WaitCallback(Ad dressOf
oSession.Thread Main), "CreateSock et")
end sub
Public Class SessionClass
Public WithEvents SocketClient As SocketTools.Soc ketWrench
Public Sub ThreadMain(ByVa l data As Object)
Dim nResult As Integer
Dim Message As String
Message = CType(data, String)
If Message = "CreateSock et" Then
CreateSocket()
Else
nResult = SocketClient.Wr ite(Message) '--> this one is send
out to cllient fine
End If
End Sub
Public Sub CreateSocket()
SocketClient = New SocketTools.Soc ketWrench
SocketClient.In itialize()
If Not SocketClient.Ac cept(Handle) Then
Exit Sub
End If
'AddHandler SocketClient.On Read, AddressOf SocketClient_On Read
--> even adding this does not help
End Sub
Private Sub SocketClient_On Read(ByVal sender As Object, ByVal e As
System.EventArg s) Handles SocketClient.On Read
Dim x As Integer
x = 1 '---> this event never gets fired
End Sub 3 2120
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_On Read event did not get fired. How can I fix this problem ? Thank you.
Imports SocketTools.Soc ketWrench.Error Code
Private WithEvents Socket As SocketTools.Soc ketWrench
Private Sub ServerForm_Load (ByVal sender As System.Object, ByVal e As System.EventArg s) 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.Soc ketWrench If Not Socket.IsInitia lized Then Throw New System.Exceptio n("Unable to initialize SocketWrench class") End If : end sub
Private Sub ListenButton_Cl ick(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles ListenButton.Cl ick If Socket.IsListen ing Then Socket.Disconne ct() Else Dim strLocalAddress As String Dim nLocalPort As Integer
strLocalAddress = LocalAddress.Te xt.Trim() nLocalPort = Val(LocalPort.T ext) Socket.Blocking = False If Not Socket.Listen(s trLocalAddress, nLocalPort) Then exit sub end if end sub
Private Sub Socket_OnAccept (ByVal sender As Object, ByVal e As SocketTools.Soc ketWrench.Accep tEventArgs) Handles Socket.OnAccept Dim oSession As SessionClass
oSession = New SessionClass oSession.Handle = e.Handle ThreadPool.Queu eUserWorkItem(N ew WaitCallback(Ad dressOf oSession.Thread Main), "CreateSock et") end sub
Public Class SessionClass Public WithEvents SocketClient As SocketTools.Soc ketWrench
Public Sub ThreadMain(ByVa l data As Object) Dim nResult As Integer Dim Message As String
Message = CType(data, String) If Message = "CreateSock et" Then CreateSocket() Else nResult = SocketClient.Wr ite(Message) '--> this one is send out to cllient fine End If End Sub
Public Sub CreateSocket() SocketClient = New SocketTools.Soc ketWrench SocketClient.In itialize()
If Not SocketClient.Ac cept(Handle) Then Exit Sub End If 'AddHandler SocketClient.On Read, AddressOf SocketClient_On Read --> even adding this does not help End Sub
Private Sub SocketClient_On Read(ByVal sender As Object, ByVal e As System.EventArg s) Handles SocketClient.On Read 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.Sock ets 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.co m> wrote in message
news:11******** **************@ f6g2000cwb.goog legroups.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_On Read event did not get fired. How can I fix this problem ? Thank you.
Imports SocketTools.Soc ketWrench.Error Code
Private WithEvents Socket As SocketTools.Soc ketWrench
Private Sub ServerForm_Load (ByVal sender As System.Object, ByVal e As System.EventArg s) 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.Soc ketWrench If Not Socket.IsInitia lized Then Throw New System.Exceptio n("Unable to initialize SocketWrench class") End If : end sub
Private Sub ListenButton_Cl ick(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles ListenButton.Cl ick If Socket.IsListen ing Then Socket.Disconne ct() Else Dim strLocalAddress As String Dim nLocalPort As Integer
strLocalAddress = LocalAddress.Te xt.Trim() nLocalPort = Val(LocalPort.T ext) Socket.Blocking = False If Not Socket.Listen(s trLocalAddress, nLocalPort) Then exit sub end if end sub
Private Sub Socket_OnAccept (ByVal sender As Object, ByVal e As SocketTools.Soc ketWrench.Accep tEventArgs) Handles Socket.OnAccept Dim oSession As SessionClass
oSession = New SessionClass oSession.Handle = e.Handle ThreadPool.Queu eUserWorkItem(N ew WaitCallback(Ad dressOf oSession.Thread Main), "CreateSock et") end sub
Public Class SessionClass Public WithEvents SocketClient As SocketTools.Soc ketWrench
Public Sub ThreadMain(ByVa l data As Object) Dim nResult As Integer Dim Message As String
Message = CType(data, String) If Message = "CreateSock et" Then CreateSocket() Else nResult = SocketClient.Wr ite(Message) '--> this one is send out to cllient fine End If End Sub
Public Sub CreateSocket() SocketClient = New SocketTools.Soc ketWrench SocketClient.In itialize()
If Not SocketClient.Ac cept(Handle) Then Exit Sub End If 'AddHandler SocketClient.On Read, AddressOf SocketClient_On Read --> even adding this does not help End Sub
Private Sub SocketClient_On Read(ByVal sender As Object, ByVal e As System.EventArg s) Handles SocketClient.On Read 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.Sock ets 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.sock et 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******** ******@TK2MSFTN GP04.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.co m> wrote in message news:11******** **************@ f6g2000cwb.goog legroups.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_On Read event did not get fired. How can I fix this problem ? Thank you.
Imports SocketTools.Soc ketWrench.Error Code
Private WithEvents Socket As SocketTools.Soc ketWrench
Private Sub ServerForm_Load (ByVal sender As System.Object, ByVal e As System.EventArg s) 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.Soc ketWrench If Not Socket.IsInitia lized Then Throw New System.Exceptio n("Unable to initialize SocketWrench class") End If : end sub
Private Sub ListenButton_Cl ick(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles ListenButton.Cl ick If Socket.IsListen ing Then Socket.Disconne ct() Else Dim strLocalAddress As String Dim nLocalPort As Integer
strLocalAddress = LocalAddress.Te xt.Trim() nLocalPort = Val(LocalPort.T ext) Socket.Blocking = False If Not Socket.Listen(s trLocalAddress, nLocalPort) Then exit sub end if end sub
Private Sub Socket_OnAccept (ByVal sender As Object, ByVal e As SocketTools.Soc ketWrench.Accep tEventArgs) Handles Socket.OnAccept Dim oSession As SessionClass
oSession = New SessionClass oSession.Handle = e.Handle ThreadPool.Queu eUserWorkItem(N ew WaitCallback(Ad dressOf oSession.Thread Main), "CreateSock et") end sub
Public Class SessionClass Public WithEvents SocketClient As SocketTools.Soc ketWrench
Public Sub ThreadMain(ByVa l data As Object) Dim nResult As Integer Dim Message As String
Message = CType(data, String) If Message = "CreateSock et" Then CreateSocket() Else nResult = SocketClient.Wr ite(Message) '--> this one is send out to cllient fine End If End Sub
Public Sub CreateSocket() SocketClient = New SocketTools.Soc ketWrench SocketClient.In itialize()
If Not SocketClient.Ac cept(Handle) Then Exit Sub End If 'AddHandler SocketClient.On Read, AddressOf SocketClient_On Read --> even adding this does not help End Sub
Private Sub SocketClient_On Read(ByVal sender As Object, ByVal e As System.EventArg s) Handles SocketClient.On Read 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.Sock ets 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 a minute. The data
received is logged in a SQL Server database.
The only method I have found of reading each socket requires a thread for
each connection which blocks waiting for data. This appears to be very
inefficient as it will result in...
|
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 "SendPingAsync" that
calls the Send method using an asynchronous delegate, so as to queue
the send method on the threadpool.
Within the send 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 as I find appropriate.
I am using the socket asynchronously by calling the BeingSend and
BeginReceive calls. I would like to be able to call shutdown and close
asynchronously if possible.
|
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
handling a request.
How can I do something like this
|
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 asynchronous receive. If I slow a
connected client down by step debugging or putting Thread.Sleep() calls
between sends then the code works on the Zeon machine.
Below is pseudo code that removes all error checking, try catch, business
logic, and...
| |
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 1024 with
all values set to Null arrive. Other than examine a block of 1024 to
see if the entire block is null, is there any other way to determine if
, say a chat message "Hi Charlie" has been received completely?
|
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 IE times
out after a long time while stating opening from http://localhost:7765...
I have a main thread that starts TCPListener and listens and accepts the
connection and queues a worker thread to handle the socket transmission:
|
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
communication. It will be called by a multithreaded server application
to send some data to an another server ( which is a linux server ).
|
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 to create a Socket object for each connection and do a
BeginReceive on each socket to handle the responses. (it is clean and
I can avoid the hassles of managing my own threads)
My question is, will this scale well? Or is there a more efficient...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |