|
-
Sep 30th, 2004, 10:16 PM
#1
Thread Starter
Hyperactive Member
Winsock: "Connection is forcefully rejected" error
I have written two programs, a client and server program. The client connects to the server, the server sends data and then closes the connection, then goes back to listen for more connections. The client connects fine, and everything goes like it should, but when I try to connect again (without resetting the server) I get a "Connection is forcefully rejected" error. Why? The server's state is 2 (listening).
Disiance
-
Oct 1st, 2004, 04:28 AM
#2
I have moved this thread to the general VB Questions.
Can you post your code, that may give people a better idea.
Woof
-
Oct 1st, 2004, 09:50 AM
#3
Thread Starter
Hyperactive Member
Server Code
Code:
Private Sub Form_Load()
Set WinSCK = New Winsock
WinSCK.LocalPort = 2890
WinSCK.Listen
End Sub
Private Sub Form_Unload(Cancel As Integer)
WinSCK.Close
End Sub
Private Sub WinSCK_DataArrival(ByVal bytesTotal As Long)
MsgBox bytesTotal
End Sub
Private Sub WinSCK_ConnectionRequest(ByVal requestID As Long)
WinSCK.Close
WinSCK.Accept requestID
WinSCK.SendData "P 1190"
DoEvents
WinSCK.Close
Do Until WinSCK.State = 0
DoEvents
Loop
WinSCK.Listen
End Sub
-
Oct 1st, 2004, 09:52 AM
#4
Thread Starter
Hyperactive Member
Client Code (Right now its just a server testing program, so nothing's automated)
Code:
Private Sub Command1_Click()
WinSCK.RemoteHost = "127.0.0.1"
WinSCK.RemotePort = 2890
WinSCK.Connect
Do Until WinSCK.State = 7
DoEvents
Loop
End Sub
Private Sub Command2_Click()
WinSCK.Close
Do Until WinSCK.State = 0
DoEvents
Loop
End
End Sub
Private Sub Command3_Click()
WinSCK.SendData "Test"
End Sub
Private Sub Command4_Click()
MsgBox WinSCK.State
End Sub
Private Sub Form_Unload(Cancel As Integer)
WinSCK.Close
End
End Sub
Private Sub WinSCK_DataArrival(ByVal bytesTotal As Long)
Dim MyData As String
WinSCK.GetData MyData
MsgBox MyData
End Sub
Private Sub WinSCK_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
MsgBox Description
MsgBox "Closing Winsock"
WinSCK.Close
End Sub
-
Oct 1st, 2004, 11:46 AM
#5
Member
Are you sure its closed? Maybe the loop is still going when it tries to connect. Sometimes after closing a connection i've noticed that it sits there on "Waiting to Close" (state: 9). I usually implement a timer checking all winsock controls for that state and calling the .Close method again if detected.
Just a thought..
-
Oct 1st, 2004, 11:47 AM
#6
Thread Starter
Hyperactive Member
That's why I put in the Command4 button (I know, I should name the things, but its just a testing app so ). It tells me the state of the winsock, and the state is 0 (closed). I know the server state is 2 (listening) because I have a button on that one too that tells me the state.
Disiance
-
Oct 1st, 2004, 02:16 PM
#7
Thread Starter
Hyperactive Member
Oh, also I know its a problem with the server because when I close it and reopen it the client can connect again. Then I have to reset it again, and again, and again, but each time I reopen it the client can connect (without resetting the client).
Disiance
-
Oct 2nd, 2004, 04:09 PM
#8
Thread Starter
Hyperactive Member
-
Oct 2nd, 2004, 11:37 PM
#9
maybe it needs time to process the Close event before accepting data? I notice that you have two ways to do this already, but nothing after the first line of the WinSCK_ConnectionRequest
-
Oct 3rd, 2004, 05:01 AM
#10
Registered User
That happend to me once but it was because of my firewall, its just a thought but maybe it may help.
-
Oct 3rd, 2004, 01:56 PM
#11
Thread Starter
Hyperactive Member
Well, I tried adding the other Do Loop in, didn't help. I thought about it being my firewall but I'm bypassing it (I use 127.0.0.1 for IP right now). I have even altered the code so that after a connection the server would unload and reload the connection form, didn't help.
Disiance
-
Oct 3rd, 2004, 02:19 PM
#12
The picture isn't missing
Move this (server code):
DoEvents
WinSCK.Close
Do Until WinSCK.State = 0
DoEvents
Loop
WinSCK.Listen
to the Winsock_SendComplete event (removing the do loop and the doevents.
You don't need this in the client code:
Do Until WinSCK.State = 7
DoEvents
Loop
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Oct 3rd, 2004, 02:31 PM
#13
Thread Starter
Hyperactive Member
Originally posted by BuggyProgrammer
Move this (server code):
DoEvents
WinSCK.Close
Do Until WinSCK.State = 0
DoEvents
Loop
WinSCK.Listen
to the Winsock_SendComplete event (removing the do loop and the doevents.
You don't need this in the client code:
Do Until WinSCK.State = 7
DoEvents
Loop
Ok, havn't tried it so I'm not sure it works, but eventually I do want to send more than one message to the client before disconnecting, should I add a counter to count the number of messages sent?
Disiance
-
Oct 3rd, 2004, 02:59 PM
#14
When does the error occur exactly? Does it connect at all?
It may be that you have a Firewall which is not allowing the app to make a connection. That situation would produce a "...connection forcefully rejected" error.
-
Oct 3rd, 2004, 03:26 PM
#15
Thread Starter
Hyperactive Member
Originally posted by baja_yu
When does the error occur exactly? Does it connect at all?
It may be that you have a Firewall which is not allowing the app to make a connection. That situation would produce a "...connection forcefully rejected" error.
The client connects just fine, receives the data, and then disconnects. I get the error when it tries to connect a 2nd time. The only way to fix it that I've found is to close the server program and start it again.
Disiance
-
Mar 18th, 2024, 04:32 PM
#16
Addicted Member
Re: Winsock: "Connection is forcefully rejected" error
 Originally Posted by Disiance
The client connects just fine, receives the data, and then disconnects. I get the error when it tries to connect a 2nd time. The only way to fix it that I've found is to close the server program and start it again.
Disiance
I know it's an old post, but I got the same error with same description.
Did you manage to solve it?
Thanks!
-
Mar 18th, 2024, 04:49 PM
#17
Fanatic Member
Re: Winsock: "Connection is forcefully rejected" error
 Originally Posted by beic
I know it's an old post, but I got the same error with same description.
Did you manage to solve it?
Thanks! 
As their last activity (check their profile) was 10 years ago, you probably won't get a response. The right thing to have done here is starting a new post describing your own issue and referencing this one so people know you've looked here.
-
Mar 18th, 2024, 05:24 PM
#18
Re: Winsock: "Connection is forcefully rejected" error
 Originally Posted by beic
I know it's an old post, but I got the same error with same description.
Did you manage to solve it?
Thanks! 
The server implementation in this thread is bonkers. You don’t accept incomming connections on the listening socket they do.
Better start a new thread titled “How to write simple TCP server using Winsock control - samples” or similar.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|