How can I connect to a winsock server that will have multiple connections? I cannot figure out how the ports would work for something like this. Only one person can be connected per port, correct? I have tried many things...any ideas? If you need more info just ask. Thanks.
Last edited by ddivers; Sep 11th, 2002 at 06:23 PM.
This is what I use to initialize. The server portion is going to have the option for up to 10 connections, ports 1001-1011. I cannot figure out how to make it attempt to connect to port 1001, if that fails, move on to 1002, then 1003, etc. and have it stop when it connects.
Last edited by ddivers; Sep 11th, 2002 at 10:50 AM.
In your example, you would need a listener for every port that the client controls are attempting to connect to.
The server only needs 1 listener tcpServer(0). As connection requests come in, load a new tcpServer(n) as needed and accept the request with the new winsock control. All will connect using the same port that the listener is using.
The Data_Arrival sub provides the index to the correct control.
Try playing around with the attached app, you will see what I am talking about. You will have to change the RemostHost in the client code, and you may have to change the port number in both.
Originally posted by ddivers Not only is it working, but I understand WHY it is working. Thanks a bunch!
Thanks I'm glad it helped. I have been working on that to be a tutorial of sorts on sockets programming and sending data structures in a mixed platform/language environment.
The way my program is set up, I have 1 server and 10 clients. Each of the clients will be able to communicate with the server, and the server only. I would like to be able to have a new form be created each time a new client connects. As it is now, I have no trouble communicating with the 10 client programs, but all 10 of my display/send text boxes are on the same form. Is there some way I can create a form control array? If you need any more information, please ask.
Sure! I do it with MDI child forms in one of my apps. I keep an Access database with info about the production machines that we have and use the info to build several menus in the parent form. Then based on the menu item selected, I load a form for the selected system.
In my parent form, I declare the forms as:
VB Code:
Dim NewStatus(giMaxNodes) As frmStatus
Dim NewExceptions(giMaxNodes) As frmExceptions
Dim NewRequest(giMaxMoniForms) As frmMoniRequest
Here is the entire menu click code that will load Process Exceptions form for the selected system.
Each form builds the UDT to be sent to the host, but all of the sockect I/O is done in the parent form. I use the form's Tag property to store the index to the form. The form stores it's Tag in a field in the 52 byte header of the UDT so that the parent knows were to send the reply info.