473,797 Members | 3,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help - Socket get nuts

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 rcvSocketMessag es() 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 rcvSocketMessag es(ByVal ar As IAsyncResult)
Try
Dim BytesRead As Integer
Dim strTempMesg As String

If (Not mySocket Is Nothing) Then
If (mySocket.Conne cted) Then

BytesRead = CurSocket.EndRe ceive(ar)
strTempMesg = Encoding.ASCII. GetString(Buffe r, 0, BytesRead)
'Do something with strTempMsg

CurSocket.Begin Receive(Buffer, 0, READ_BUFFER_SIZ E,
SocketFlags.Non e, AddressOf rcvSocketMessag es, Nothing)

Else
forceSocketDisc onnection()
End If
Else
'forceSocketDis connection()
End If

Catch e As Exception
'catch error
End Try
Nov 21 '05 #1
2 1133
as fact as i understand. can u removed those two (2)
forceSocketDisc onnection() ? u cannot put forceSocketDisc onnection()
after CurSocket.Begin Receive. i think u can put
forceSocketDisc onnection() before CurSocket.Begin Receive . the code i
used: also i added ondisconect.

Private Sub sockDataArrival (ByVal ar As IAsyncResult)
Dim state As StateObject = CType(ar.AsyncS tate, StateObject)
Dim client As Socket = state.workSocke t
Dim bytesRead As Integer

Try
bytesRead = client.EndRecei ve(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(32 767)

client.BeginRec eive(state.buff er, 0, state.BufferSiz e, 0,
AddressOf sockDataArrival , state)
RaiseEvent onDataArrival(D ata, bytesRead)
Catch
RaiseEvent onError(Err.Des cription)
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 rcvSocketMessag es() 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 rcvSocketMessag es(ByVal ar As IAsyncResult)
Try
Dim BytesRead As Integer
Dim strTempMesg As String

If (Not mySocket Is Nothing) Then
If (mySocket.Conne cted) Then

BytesRead = CurSocket.EndRe ceive(ar)
strTempMesg = Encoding.ASCII. GetString(Buffe r, 0, BytesRead)
'Do something with strTempMsg

CurSocket.Begin Receive(Buffer, 0, READ_BUFFER_SIZ E,
SocketFlags.Non e, AddressOf rcvSocketMessag es, Nothing)

Else
forceSocketDisc onnection()
End If
Else
'forceSocketDis connection()
End If

Catch e As Exception
'catch error
End Try


Nov 21 '05 #2
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)
forceSocketDisc onnection() ? u cannot put forceSocketDisc onnection()
after CurSocket.Begin Receive. i think u can put
forceSocketDisc onnection() before CurSocket.Begin Receive . the code i
used: also i added ondisconect.

Private Sub sockDataArrival (ByVal ar As IAsyncResult)
Dim state As StateObject = CType(ar.AsyncS tate, StateObject)
Dim client As Socket = state.workSocke t
Dim bytesRead As Integer

Try
bytesRead = client.EndRecei ve(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(32 767)

client.BeginRec eive(state.buff er, 0, state.BufferSiz e, 0,
AddressOf sockDataArrival , state)
RaiseEvent onDataArrival(D ata, bytesRead)
Catch
RaiseEvent onError(Err.Des cription)
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 rcvSocketMessag es() 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 rcvSocketMessag es(ByVal ar As IAsyncResult)
Try
Dim BytesRead As Integer
Dim strTempMesg As String

If (Not mySocket Is Nothing) Then
If (mySocket.Conne cted) Then

BytesRead = CurSocket.EndRe ceive(ar)
strTempMesg = Encoding.ASCII. GetString(Buffe r, 0, BytesRead)
'Do something with strTempMsg

CurSocket.Begin Receive(Buffer, 0, READ_BUFFER_SIZ E,
SocketFlags.Non e, AddressOf rcvSocketMessag es, Nothing)

Else
forceSocketDisc onnection()
End If
Else
'forceSocketDis connection()
End If

Catch e As Exception
'catch error
End Try


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5574
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"; $port = "8080"; $url = "http://www.myhost.com/folder/script.dll?variable=hello";
4
2761
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 NICs but the one i want to use. Of course i tried to use Socket.Bind method, but even if i use it to bind to the correct NIC (I also verify using LocalEndPoint and IT IS the correct one), the packet is sent on the wrong NIC! (I have a software...
3
3713
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 Windows XP has. My program can connect to any other port (that I've tried) on a remote machine. However, when trying to connect to port 25 (SMTP), immediately, socket error 10053 occurs, and the socket fails to connect because of it. The problem is...
3
1420
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 function within my DLL in the VC++ project. I've been reading document over the internet and this
0
1058
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 NICs but the one i want to use. Of course i tried to use Socket.Bind method, but even if i use it to bind to the correct NIC (I also verify using LocalEndPoint and IT IS the correct one), the packet is sent on the wrong NIC! (I have a software...
1
1438
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 the server, where the server responds back with the same # bytes. i set this value to 441 bytes (so that it is an odd number). the server receives 8,000 bytes. always. no matter what. every single time. i send 441 bytes 1 time and the server...
2
2466
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 server, server reasoned, and so on... The thing is that connection MUST always stay open. I'm using C++, and as for sockets, I'm using native syscalls, not MFC. I'm using stream sockets for communication. Another thing is that is should work both...
5
15729
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 to read data from the transport connection" when restart reading the stream with socket.BeginRead in the Sub SocketIncomingMsg. I'm debugging now for weeks, but I can't detect where it's
6
2986
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 them. to be more clear we process this purpose we serve this to the student in the university. how?? student will send a message that contains his name,id and request by format the server want such as zaina-20024008-grade. the grade is the request...
0
9685
marktang
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...
0
9536
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,...
0
10468
Oralloy
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...
1
10205
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,...
0
9063
agi2029
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...
1
7559
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
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();...
2
3748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2933
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.