Hi,
I hope you can help me with this one (my code is below my message).
I have many clients connecting to my server. When any of them
disconnect, something happen.
This user get disconnect from the server and this is fine. But
sometime, I can't reproduce exactly the situation (maybe the client
crashed), the related socket in server seems to get nuts and still think
that it is connected to the client.
Here is my part of the code that contain a possible bug... The socket
keep calling rcvSocketMessages() to infinity. It receive an empty ""
character in strTempMesg.
What I don't understand, it is why is pass through the first and second
"if" that concern the mySocket state. Should it be able to detect that
the client is no more there?
Do you have any idea why the mySocket keep its connected state?
I hope my explanation was clear, otherwise, ask me and I'll answer your
question. I really have to correct this problem.
Thank you very much.
Marty
Private mySocket As Socket
Private Sub rcvSocketMessages(ByVal ar As IAsyncResult)
Try
Dim BytesRead As Integer
Dim strTempMesg As String
If (Not mySocket Is Nothing) Then
If (mySocket.Connected) Then
BytesRead = CurSocket.EndReceive(ar)
strTempMesg = Encoding.ASCII.GetString(Buffer, 0, BytesRead)
'Do something with strTempMsg
CurSocket.BeginReceive(Buffer, 0, READ_BUFFER_SIZE,
SocketFlags.None, AddressOf rcvSocketMessages, Nothing)
Else
forceSocketDisconnection()
End If
Else
'forceSocketDisconnection()
End If
Catch e As Exception
'catch error
End Try 2 1114
as fact as i understand. can u removed those two (2)
forceSocketDisconnection() ? u cannot put forceSocketDisconnection()
after CurSocket.BeginReceive. i think u can put
forceSocketDisconnection() before CurSocket.BeginReceive . the code i
used: also i added ondisconect.
Private Sub sockDataArrival(ByVal ar As IAsyncResult)
Dim state As StateObject = CType(ar.AsyncState, StateObject)
Dim client As Socket = state.workSocket
Dim bytesRead As Integer
Try
bytesRead = client.EndReceive(ar)
Catch
Exit Sub
End Try
Try
Dim Data() As Byte = state.buffer
If bytesRead = 0 Then
client.Shutdown(SocketShutdown.Both)
client.Close()
RaiseEvent onDisconnect()
Exit Sub
End If
ReDim state.buffer(32767)
client.BeginReceive(state.buffer, 0, state.BufferSize, 0,
AddressOf sockDataArrival, state)
RaiseEvent onDataArrival(Data, bytesRead)
Catch
RaiseEvent onError(Err.Description)
Exit Sub
End Try
End Sub
Marty wrote: Hi,
I hope you can help me with this one (my code is below my message).
I have many clients connecting to my server. When any of them disconnect, something happen.
This user get disconnect from the server and this is fine. But sometime, I can't reproduce exactly the situation (maybe the client crashed), the related socket in server seems to get nuts and still think that it is connected to the client.
Here is my part of the code that contain a possible bug... The socket keep calling rcvSocketMessages() to infinity. It receive an empty "" character in strTempMesg.
What I don't understand, it is why is pass through the first and second "if" that concern the mySocket state. Should it be able to detect that the client is no more there?
Do you have any idea why the mySocket keep its connected state?
I hope my explanation was clear, otherwise, ask me and I'll answer your question. I really have to correct this problem.
Thank you very much.
Marty
Private mySocket As Socket
Private Sub rcvSocketMessages(ByVal ar As IAsyncResult) Try Dim BytesRead As Integer Dim strTempMesg As String
If (Not mySocket Is Nothing) Then If (mySocket.Connected) Then
BytesRead = CurSocket.EndReceive(ar) strTempMesg = Encoding.ASCII.GetString(Buffer, 0, BytesRead) 'Do something with strTempMsg
CurSocket.BeginReceive(Buffer, 0, READ_BUFFER_SIZE, SocketFlags.None, AddressOf rcvSocketMessages, Nothing)
Else forceSocketDisconnection() End If Else 'forceSocketDisconnection() End If
Catch e As Exception 'catch error End Try
Thanks Supra,
It resolve my bug, and I'm gonna do more tests.
Have a nice day! :)
Marty
Supra wrote: as fact as i understand. can u removed those two (2) forceSocketDisconnection() ? u cannot put forceSocketDisconnection() after CurSocket.BeginReceive. i think u can put forceSocketDisconnection() before CurSocket.BeginReceive . the code i used: also i added ondisconect.
Private Sub sockDataArrival(ByVal ar As IAsyncResult) Dim state As StateObject = CType(ar.AsyncState, StateObject) Dim client As Socket = state.workSocket Dim bytesRead As Integer
Try bytesRead = client.EndReceive(ar) Catch Exit Sub End Try
Try Dim Data() As Byte = state.buffer If bytesRead = 0 Then client.Shutdown(SocketShutdown.Both) client.Close() RaiseEvent onDisconnect() Exit Sub End If ReDim state.buffer(32767)
client.BeginReceive(state.buffer, 0, state.BufferSize, 0, AddressOf sockDataArrival, state) RaiseEvent onDataArrival(Data, bytesRead) Catch RaiseEvent onError(Err.Description) Exit Sub End Try
End Sub
Marty wrote:
Hi,
I hope you can help me with this one (my code is below my message).
I have many clients connecting to my server. When any of them disconnect, something happen.
This user get disconnect from the server and this is fine. But sometime, I can't reproduce exactly the situation (maybe the client crashed), the related socket in server seems to get nuts and still think that it is connected to the client.
Here is my part of the code that contain a possible bug... The socket keep calling rcvSocketMessages() to infinity. It receive an empty "" character in strTempMesg.
What I don't understand, it is why is pass through the first and second "if" that concern the mySocket state. Should it be able to detect that the client is no more there?
Do you have any idea why the mySocket keep its connected state?
I hope my explanation was clear, otherwise, ask me and I'll answer your question. I really have to correct this problem.
Thank you very much.
Marty
Private mySocket As Socket
Private Sub rcvSocketMessages(ByVal ar As IAsyncResult) Try Dim BytesRead As Integer Dim strTempMesg As String
If (Not mySocket Is Nothing) Then If (mySocket.Connected) Then
BytesRead = CurSocket.EndReceive(ar) strTempMesg = Encoding.ASCII.GetString(Buffer, 0, BytesRead) 'Do something with strTempMsg
CurSocket.BeginReceive(Buffer, 0, READ_BUFFER_SIZE, SocketFlags.None, AddressOf rcvSocketMessages, Nothing)
Else forceSocketDisconnection() End If Else 'forceSocketDisconnection() End If
Catch e As Exception 'catch error End Try
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: b_prikls |
last post by:
Hi all,
i need your help, here is code, that makes http connection to a
website throu
a proxy server, and it works fine:
==========================================
$proxy = "111.111.111.111";...
|
by: 0k |
last post by:
Hi everyone, I am trying to write a small app that sends multicast udp
packets using a socket object.
I have more than one NIC on my PC and the following code works OK only if I
disable all the...
|
by: Billism |
last post by:
My email client (I programmed) recently has stopped being able to send
email with my XP machine. I have had 3 other friends test it and the same
thing happens. The program has not changed, but...
|
by: Marty |
last post by:
Hi,
I have this DLL made with VB.NET made as a Class Library project. I
know this is managed code.
I have my other made with VC++.NET, unmanaged code.
The point is that I want to use...
|
by: 0k |
last post by:
Hi everyone, I am trying to write a small app that sends multicast udp
packets using a socket object.
I have more than one NIC on my PC and the following code works OK only if I
disable all the...
|
by: |
last post by:
one thing to keep in mind is that i've written multiple
tcp apps in .net 2002 and 2003, and haven't seen this
problem before. I have a simple socket app where a
client sends some # of bytes to...
|
by: ne.seri |
last post by:
In short, I'm building a kind of server which is supposed to handle
open connections with clients. E.g. client connects to the server, the
connection stays open, client sends a request to the...
|
by: Arno |
last post by:
reposted with the right microsoft managed newsgroup ID: Sorry for the
inconvinience
Hi,
I've written a class for client-socket connection, but I get a lot of times
the error message "Unable...
|
by: zaina |
last post by:
hi everybody
i am nwebie in this forum but i think it is useful for me and the member are helpful
my project is about connecting client with the server to start exchanging messages between...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
| |