|
-
Mar 8th, 2007, 08:10 AM
#1
-
Mar 8th, 2007, 12:36 PM
#2
Re: NetWork Connection not working sometimes?
Since you can only have one connection on one socket, the most likely problem is that you're not closing a socket sometimes. Check the clients as well as the server.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Mar 8th, 2007, 02:16 PM
#3
Re: NetWork Connection not working sometimes?
OK, did some more reading thru related threads.
What I'm doing is this:
The Server has a WinsockTCP(1-5) array with each WinsockTCP(i) having a different (and therefore identifying) Portnumber. The Server is listening on all WinsockTCP(i) and on a ConnectionRequest accepting the connection on that connection [I think the problem is here!]. the connection remains open as long as the application is running, if the server is closed, the connections are closed and the clients close themself.
From the reading it sounds like that I don't need a different Portnumber for each array item and that I should use only one array item to listen for connection requests. Is that correct?
I'm using the this WinsockTCP array in a way where on each GetData Event the Index is telling Who did send something. So if I only use one listening connection (for example Indexnumber 0), how would I accept the connection from a client (for example the that should use Indexnumber 2?)Would all array-items need to use the same portnumber? How could the server identify if a message would be coming from connectionIndexnumber 2 or 3?
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Mar 8th, 2007, 05:26 PM
#4
Re: NetWork Connection not working sometimes?
This is from a piece of code I downloaded from somewhere. It has a single Winsock control on the form with Index set to 0
Code:
Private Sub wsServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Dim Socket As Integer
Socket = wsServer().UBound + 1
Load wsServer(Socket)
wsServer(Socket).Accept requestID
End Sub
 Originally Posted by opus
Would all array-items need to use the same portnumber?
Yes - and that makes it easier for the client, since all copies use the same code.
How could the server identify if a message would be coming from connectionIndexnumber 2 or 3?
Code:
Private Sub wsServer_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Index tells you which control the data is coming in on.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Mar 9th, 2007, 01:16 AM
#5
Re: NetWork Connection not working sometimes?
Thanks for the reply Al42
I got it that far.
Although I'm using different portnumbers for each array-item winsock, i can use the same code for them (they are an array even with different portnumbes).
However my identification problem starts a bit earlier, each client has a specific type, so the server must be able to ident a client already in the connectiorequest event. Since all clients should use the same port, for the server the connetionrequests will all look the same. Is there a way to ID the connectiorequest, or do I have to generate an "identification-message" just after the connection?
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Mar 9th, 2007, 06:29 PM
#6
Re: NetWork Connection not working sometimes?
Have the client send a "I'm Type A" or "I'm Type B" (or however you want to do it) connection string. Then the server will know, at the connection request, what type the client is.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Mar 11th, 2007, 11:32 AM
#7
Re: NetWork Connection not working sometimes?
Hi, Al42, seems you're also "working"on the weekend.
Thanks for all the help on this topic, as a matter of fact I already use such a "I'm type A" message, and this part works.
But I'm still stuck with the problem that the connection (and it is the TCP one) will not work if I run the software more than once on a machine without a reboot in between. and that happens on the "testing ground", that is one computer where all applications are running using the loopback IP .
So far I haven't been able to find the exact reproducing way, but I'll keep on trying.
The routines for closing the connections and applications are as follows
For both the Server and Clients (the Server NetzwerkFunction = Control).
Client will call mnu_quit, the Server will keep on listening!
Code:
Private Sub WinSockTCP_Close(Index As Integer)
Dim i As Integer
On Error GoTo errorhandler
WinSockTCP(Index).Close
WinSockTCP(Index).Listen
If Not NetzwerkFunction = Control Then
Timer1 = False
mnuQuit_Click
End If
Exit Sub
errorhandler:
ErrLog_schreiben "WinSockTCP_Close", Index
Resume Next
End Sub
The Form_Unload is called via Mnu_quit for Server and Clients.
Code:
Private Sub mnuQuit_Click()
On Error GoTo errorhandler
If mnuStartStop.Caption = "S&top" Then Timer1 = False
Unload MainForm
End
Exit Sub
errorhandler:
ErrLog_schreiben "mnuQuit_Click"
Resume Next
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim fs As Object
Dim i As Integer
On Error GoTo errorhandler
For i = 0 To 4
WinSockTCP(i).Close
Next i
For i = 0 To 2
WinsockUDP(i).Close
Next i
Unload frmCPARechner
Unload frmOptions
Unload frmReplay
Exit Sub
errorhandler:
ErrLog_schreiben "Form_Unload", Datei
Resume Next
End Sub
Is there a problem in those closing routines?
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Mar 13th, 2007, 03:06 AM
#8
Member
Re: NetWork Connection not working sometimes?
maybe this can help u understand more about multiple connections as it did also help me before...
http://www.vbforums.com/showthread.php?t=297308
I'm maybe a noob now, but with your help, i would become an expert someday 
-
Mar 13th, 2007, 10:19 AM
#9
Re: NetWork Connection not working sometimes?
FOUND the problem!
Instead of having just:
Code:
WinsockTCP(0).Connect ServerIp, ServerPort
the following solved the problem.
Code:
Connected=False
WinsockTCP(0).Connect ServerIp, ServerPort
Do
DoEvents
Loop Until Connected=True
With this line added in the winsockTCP_Connect Event
It looks like this DoEvents solved the starting problem (Clients not connecting sometimes). So the change in the usage of ports wasn't really neccesary, but I did learn a bit more about Winsock.
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
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
|