0
votes

I am wondering what is the best stable way to handle multiple connections at the same time?

I am using vb6 and currently using winsock api's no Winsock control. I tried that before and its not multi threaded too.

At the moment it's only a single thread which is not efficient when the thread is busy sending data the other connector is delayed. Until the thread be free.

I am using WSAAsyncSelect non-blocking socket.

So since VB6 isn't stable at multithreading. I am thinking of using an ASM DLL and then call it from vb6 that will handle the connections. But what is the best way? create a thread for each connection then terminate the thread after recv? or keep the connection open all time until the other part closes it?

Because the server running the client is not that good specifications. So more threads consumes more resources.

i have not much knowledge about what is better in performance so please share your opinions.

Also how to be sure that all data have been sent from send function on a non-blocking sockets?

should loop through send and count each time how many bytes sent? or just call it once? i have noticed if i send large data that can not be processed at 1 time the window that i specified at call to WSAAsyncSelect to handle the network events gets called again so there is more data to be sent but how to be sure that this is belongs to this partial send? or recv?

Note: Max connections can be connected at same time is about 100.

Here is an example of problem i am having while sending a pic over network size (5 kb) sometimes it is all received with 1 recv call while sometimes its being split into pieces

If Bytes = PicSize Then


        MsgBox "All data are sent 1 time"
        Else
            MsgBox "there is more data left"
            While Bytes <> PicSize
                bytesRecieved = recv(s, Buffer(Bytes), UBound(Buffer), 0)
                If bytesRecieved > 0 Then
                    Bytes = Bytes + bytesRecieved
                End If
                DoEvents
            Wend
        End If

The return value of recv is always WSAEWOULDBLOCK so i am getting inside an infinite loop. Any suggestions?

1
MASM? Assembler? Also: is your VB6 guy an application or a DLL? - Euro Micelli
Yes MASM assembler. My vb6 is application EXE receives connections. Can not get it multi threaded. I tried everything still crashing sometimes. Not safe. - a man in love
Multithreading in VB6 means starting the same application more than once ;) The VB6-way to solve such a problem is to get yourself a neat component. Chilkat Socket, for example, which works asynchronously, so even a single thread should be able to handle a lot of conections. - user414873
People have accomplished thousands of simultaneous TCP connections to one server written in VB6 using the Winsock control, though such servers did trivial echos and were only meant for demonstration. A server doing something practical but not too intensive handling several hundred shouldn't be a problem. The Winsock control is async and has excellent performance, I suggest you look at your own program structure first. - Bob77

1 Answers

1
votes

You've ask more than one question, which makes it hard to answer. Whether using async winsock directly or using the WinSock control, it is important to realize that when you think you are "busy sending data" all you are doing is passing the data to the network stack. This happens quickly and your code continues on. That data will, hopefully, eventually, make it to the destination. This part does not happen as quickly, but your code has moved on to process the next task.