wqweto / VbAsyncSocket

Sockets with pure VB6 impl of TLS encryption
MIT License
166 stars 33 forks source link

[Improvement] More simple samples on separate Client-Server apps #7

Closed dragokas closed 4 years ago

dragokas commented 4 years ago

Suggestion:

client-server

to have more minimalistic samples. Projects attached. Winsock-simple.zip

Also, don't you mind to clarify:

1) do I correctly stop the connection:

Private Sub cmdStop_Click()
    Dim i&
    For i = 0 To ctxServer.UBound
        If Not (ctxServer(i) Is Nothing) Then
            ctxServer(i).Close_
        End If
    Next

2) Comparing to Chat\Project1.vbp sample, where user control is not used, what is a difference? Is that mean, it is not multithreaded, so some side-effects are expected?

Thank you.

wqweto commented 4 years ago
  1. Yes, server stop looks ok. This will probably unload the control in CloseEvent too. (You can remove Close event impl as there is no Close event at all).
  2. You don't need a Winsock control per se, it's a crutch for those familiar with VB6 provided one. You can directly use cAsyncSocket (or cTlsSocket) to establish socket connections

cTlsSocket is source-compatible with cAsyncSocket meaning that if some code is using plain TCP connections with cAsyncSocket it can easily be migrated to TLS secured ones by just replacing the socket class w/ cTlsSocket.

Btw, there is a long-standing TODO to migrate chat sample to optional secure sockets w/ cTlsSocket. Unfortunately DTLS (the TLS over UDP) is not implemented yet.

dragokas commented 4 years ago

I see, thanks. Unfortunately, I don't familiar with old known socket control. But, I see the reason :) Сonveniently +1

However, what if the main thread busy with some time-consuming operation, let's say 1 sec (or some amount of time > timeout), and during this time net packet is incoming? Does user control version have a benefit in such case? I didn't test yet this case, though.

wqweto commented 4 years ago

When main UI thread is busy no socket events can be received on this main UI thread so communication is paused until main thread can pump messages (becomes available) again. There is no difference in this behavior between MS Winsock controll, cAsyncSocket class and ctxWinsock replacement control.

dragokas commented 4 years ago

Updated GET samples. Thanks a lot for your detailed explanation in PM.

Winsock-simple.zip

946896

Remains to do a fix for HTTPS to make it work...

wqweto commented 4 years ago

In ctxWinsock_DataArrival you don't need ctxWinsock.PeekData sBuffer before call to actual GetData method.

The PeekData method only peeks at recv buffer without removing the data from recv buffer. It is left in sample probably because I've been debugging it. Sorry about that!

wqweto commented 4 years ago

Project added under samples directory in 4dc96d32677ef7f473d180b922a6ab543647683e

10x!