Frantic-
02-24-2005, 04:35 PM
anyone know who to have multiple connections to a single server? Sofar I can only have one user connected to my server, and its not fun to talk to your self.
multiple connections to port?Frantic- 02-24-2005, 04:35 PM anyone know who to have multiple connections to a single server? Sofar I can only have one user connected to my server, and its not fun to talk to your self. Illusionist 02-24-2005, 05:12 PM you can use a winsock array (http://www.xtremevbtalk.com/search.php?searchid=1402891) also have a look at WinsockVB:Receive multiple connections (http://winsockvb.com/article.php?article_id=18) WinsockVB:Winsock control arrays (http://winsockvb.com/article.php?article_id=19) Frantic- 02-24-2005, 05:26 PM Finally some one answers to one of my posts here! ive been waiting for hours!!! Ok, I actualy just started learning Winsock last night, and i learned what I know so far from winsockvb.com. I got up to the multiple connections tut, and this is where i got lost. I could not follow that at all, it was very poorly written. I got the basic idea down, but since Im totaly new to this, and visual basic in general (5 months) it didnt really help much. This is what I got after reading those tutorials, and surfing the web for about 5 hours. I am stuck on an error message that says: "Procedure does not match description of event or procedure having same name " It points to the top line of code that I have include below. Private sub .... Private Sub Winsock_ConnectionRequest(Index As Integer, ByVal RequestID As Long) For i = 0 To UBound(Winsock) Next i Winsock.Close Winsock.Accept RequestID End Sub End Sub I dont know where to go from here. Illusionist 02-24-2005, 05:42 PM you have to set the index property on your control to 0 on your form and then your going to want to change those to Winsock(Index).whatever and maybe you should go back and re-read one or both of those tutorials, i know the first one is pretty clear and clean, you've got several mistakes there. Frantic- 02-24-2005, 05:44 PM It was set to 0 when i got that error message. If i had executed the program before with it having no index, would I need to replace the old winsock with a new one? Because before when I was just having one connection It had no index value. It wasnt until I started trying to add multiple connections that I gave it an index value of 0. Ok, ive made the suggested changes, and ive come up with the same error for this code section. Private Sub Winsock_DataArrival(ByVal bytesTotal As Long) Dim strData As String Winsock.GetData strData For i = 0 To UBound(Winsock) If Winsock(i).Status = sckConnected Then Winsock(i).SendData strData DoEvents End If Next i txtConsole.Text = txtConsole.Text & vbCrLf & strData txtConsole.SelStart = Len(txtConsole.Text) End Sub Ill save time and post my whole source file here for viewing. Option Explicit Private Sub Form_Load() Winsock.LocalPort = 10101 Winsock.Listen End Sub Private Sub Winsock_ConnectionRequest(Index As Integer, ByVal RequestID As Long) Load Winsock(Winsock.UBound + 1) Winsock(Winsock.UBound).Accept RequestID For i = 0 To UBound(Winsock) Next i Winsock(Index).Close Winsock(Index).Accept RequestID End Sub Private Sub Winsock_DataArrival(ByVal bytesTotal As Long) Dim strData As String Winsock.GetData strData For i = 0 To UBound(Winsock) If Winsock(i).Status = sckConnected Then Winsock(i).SendData strData DoEvents End If Next i txtConsole.Text = txtConsole.Text & vbCrLf & strData txtConsole.SelStart = Len(txtConsole.Text) End Sub Illusionist 02-24-2005, 05:45 PM that's right, but you wouldn't have to erplace it, just take away the index. But ya go back and re-read atleast that first tutorial Frantic- 02-24-2005, 05:50 PM im reading the 1st tut again, and maybe perhaps i looked at it the wrong way. Am i supposed to at form load have the for loop just createa bunch of winsocks, and then make extra subs and or functions to manage the opening,closing and connecting to the ports, and if all are used then say "Sorry we're full " Or perhaps the above could be one way to go about it. Illusionist 02-24-2005, 06:02 PM well... you could do it that way, or as i believe that first tut i showed you makes a new control each connection request... Illusionist 02-24-2005, 06:05 PM well in your DataArrival, you need to add Index As Integer into the parameters of the sub, and then user Winsock(Index) instead of just Winsock Frantic- 02-24-2005, 06:09 PM Should I add index into parts that already have a (value) after them? UBound(Winsock) should i make it UBound(Winsock(index)) Illusionist 02-24-2005, 06:13 PM no, UBound just takes the name of the array, also in your for loop, don't change those (i) to (Index) you'll need that i to send to all connected clients Frantic- 02-24-2005, 06:30 PM ok im down to what i think if either the last or 2nd last problem, atleast with my server. I ran into another compilation error, and i tried to fix it, but ran into a second error when i "fixed" it. I will list. When i ran the code as is, i got a message saying " Method or data member not found " and it pointed to winsock.localport = 10101 and highlighted LocalPort = it pointed to the form load which is located below. Private Sub Form_Load() Winsock.LocalPort = 10101 Winsock.Listen End Sub I went and made the following changes to the form load, which are shown below. Private Sub Form_Load() Winsock(index).LocalPort = 10101 Winsock(index).Listen End Sub I got this error message. " variable not defined " and it pointed to the winsock(index).localport = 10101 and highlighted index. Illusionist 02-24-2005, 06:31 PM winsock(0) ... your first control... Frantic- 02-24-2005, 06:47 PM Updated form load: Private Sub Form_Load() Dim i As Integer For i = 1 To 5 Load Winsock(i) Next i Winsock(0).LocalPort = 10101 Winsock(0).Listen End Sub now its telling me that UBound is an expected array. Illusionist 02-24-2005, 06:51 PM don't load any to begin with, take that out, and load them like you were before in your connection request Frantic- 02-24-2005, 06:57 PM same error. "Expected Array" It it highlighting UBound found in the following code. Private Sub Winsock_DataArrival(index As Integer, ByVal bytesTotal As Long) Dim strData As String Winsock(index).GetData strData For i = 0 To UBound(Winsock) If Winsock(i).Status = sckConnected Then Winsock(i).SendData strData DoEvents End If Next i txtConsole.Text = txtConsole.Text & vbCrLf & strData txtConsole.SelStart = Len(txtConsole.Text) End Sub Illusionist 02-24-2005, 07:17 PM oops, lol use Winsock.count -1 instead, i believe it even shows that in one of those tuts Frantic- 02-24-2005, 07:20 PM Ok ive made that change, now its telling me "method or data member not found" for winsock(i).status If Winsock(i).Status = sckConnected Then Private Sub Winsock_DataArrival(index As Integer, ByVal bytesTotal As Long) Dim strData As String Winsock(index).GetData strData Dim i As Integer For i = 0 To Winsock.Count - 1 If Winsock(i).Status = sckConnected Then Winsock(i).SendData strData DoEvents End If Next i txtConsole.Text = txtConsole.Text & vbCrLf & strData txtConsole.SelStart = Len(txtConsole.Text) End Sub Illusionist 02-24-2005, 07:28 PM where did Status come from? it should be State Frantic- 02-24-2005, 07:32 PM lol, everything i know came from reading online tuts :( Ill soon be investing in some nice books, do you have any reccomendations? Ok this time it actualy compiled!!! I ran it, and logged on. The client was able to connect, but then the server generated an error dialog box saying "Invalid Control Array Index" Illusionist 02-24-2005, 07:36 PM Do you know where that error came from? Was it probably in your connection request? post your newly updated code Frantic- 02-24-2005, 07:40 PM Option Explicit Private Sub Form_Load() Winsock(0).LocalPort = 10101 Winsock(0).Listen End Sub Private Sub Winsock_ConnectionRequest(index As Integer, ByVal RequestID As Long) Load Winsock(Winsock.ubound - 1) Winsock(Winsock.ubound).Accept RequestID Winsock(index).Close Winsock(index).Accept RequestID End Sub Private Sub Winsock_DataArrival(index As Integer, ByVal bytesTotal As Long) Dim strData As String Winsock(index).GetData strData Dim i As Integer For i = 0 To Winsock.Count - 1 If Winsock(i).State = sckConnected Then Winsock(i).SendData strData DoEvents End If Next i txtConsole.Text = txtConsole.Text & vbCrLf & strData txtConsole.SelStart = Len(txtConsole.Text) End Sub I know it never got to the sendData because before when the user logged on, the servers display said "User strName has entered the room" That didnt happen when I just ran it with my new code. Illusionist 02-24-2005, 08:05 PM try making it +1 or use .count instead Frantic- 02-24-2005, 08:15 PM lol, i told you ive just spent literally all day looking for tuts and surfing message boards :D im 1 day into my learning :p Ok, i had to fool around with my code for a bit, until i found something that would let the client connect, and send messages. With this new code, I am back to where I was earlier, being able to connect One client. Here is the new updated code: Option Explicit Private Sub Form_Load() Winsock(0).LocalPort = 10101 Winsock(0).Listen End Sub Private Sub Winsock_ConnectionRequest(index As Integer, ByVal RequestID As Long) Load Winsock(Winsock.ubound + 1) Winsock(Winsock.ubound).Accept RequestID Winsock(index).Close Winsock(index).Accept RequestID End Sub Private Sub Winsock_DataArrival(index As Integer, ByVal bytesTotal As Long) Dim strData As String Winsock(index).GetData strData Dim i As Integer For i = 0 To Winsock.Count - 1 If Winsock(i).State = sckConnected Then Winsock(i).SendData strData DoEvents End If Next i txtConsole.Text = txtConsole.Text & vbCrLf & strData txtConsole.SelStart = Len(txtConsole.Text) End Sub Illusionist 02-24-2005, 08:16 PM have you tried connecting two? Frantic- 02-24-2005, 08:23 PM if it is any help, here is the display text from the client Application. the writing in the () was added by me just now to tell you what i did. --------------------------------------------------------- Attempting to connect to KLCServer... (Click Log On from Login Screen) Connected to KLCServer (Loaded the form, and executed form load) Frantic has entered the room. (Part of form load) Frantic> Testing 123... (clicked send on client app) Frantic> Testing on 2/24/05 at 10:18 pm EST (clicked send on client app) Disconnected from KLCServer (clicked disconnect on client app, winsock.close is only found on the client app, perhaps I need to also add it into the server somewhere?) Attempting to connect to KLCServer... (clicked reconnect) Error: Connection is forcefully rejected (message generate by client that connection was rejected) ----------------------------------------------------------- And here is what the display to my server looked like: ---------------------------------------------------------- Frantic has entered the room. Frantic> Testing 123... Frantic> Testing on 2/24/05 at 10:18 pm EST Frantic has left the room. ----------------------------------------------------------- Frantic- 02-24-2005, 08:24 PM ^^^^^^^^ just in case u dont notice the above, ill point it out :D and yes, i tried from, but both from my own computer, ill send my brother a copy and report results back. Illusionist 02-24-2005, 08:35 PM did 2 succesfully connect when trying from your computer? you also are going to need in your server something like Private Sub Winsock_Close(index As Integer) Winsock(index).Close End Sub and get this out of your ConnectionRequest: Winsock(index).Close Winsock(index).Accept RequestID Frantic- 02-24-2005, 08:43 PM Works!!!! Thanks A Lot Bro/sis!!! :d :d :d :d :d :d :d Illusionist 02-24-2005, 08:45 PM lol, I'd be a bro, and it's not a problem. good luck with the rest, don't hesitate to ask questions MikeJ 02-26-2005, 08:25 PM Ill soon be investing in some nice books, do you have any reccomendations? We have a collection of books recommended by our Experts in the Tutor's Corner. If I'm remembering correctly, there's one in there that covers Winsock. cooljj2003uk 02-28-2005, 04:21 AM i've written a server and client program which alows any amount of clients to connect to the server and talk to eachother. i'll post the code when i get home. |
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum