Hello all!
I'd like to present my Winsock Plugin, it's complete and fully documented using the DBP IDE help system.
The benefits:
-Winsock2.2 wrapper for TCP & UDP
-fast c++ dll (as fast as I could do
)
-easy and fast channel managing with channel-ptr
-direct memory access to packet data (read also the 0 bytes!)
-up to 3970 simultaneous connections (on my PC locally, so: 7940 connections)
-string table without decorated names
-keyword list included for DBP IDE
-help files included for DBP online help (for all
28 commands!)
-
new list of commands:
http://homepage.swissonline.ch/barnski/winsock.htm
-get help for selected commands in your DBP IDE by pushing F1!
-debug and release version (will come later, after bug squashing)
And most of all; its
free for non-commercial use!
If you like it and want to use it as part of a commercial product please send me an email to let me know. I will most likely approve it, just to keep me informed.
You will find my email and the license agreement in the zip. By using my plugin you agree to the terms stated in the license text file.
Attention: It is not yet fully tested, so please take the time to fully debug it with me. Any bug reports will be appreciated! I might also give some support if needed and if time allows it.
Ok, enough said, here is the
download link:
http://homepage.swissonline.ch/barnski/Barnski'sWinsockPlugin.zip
Download it and unzip it into your DBP install directory. Read the text files included in the zip for more information about installing and for the user license and agreement!!
Then test it and tell me what you think!
Have Fun!!
greets,
Barnski
edit; for now, you can test these examples for a client and a server, which are also included in the zip in the help section.
client:
`CLIENT
#constant CLIENTS 4000
#constant HOST_NAME "127.0.0.1"
#constant HOST_PORT 4321
set window on
winsock make
if winsock error()
print winsock error msg$()
wait key
end
endif
dim channels(CLIENTS) as DWORD
connected = 0
print "hit enter to start connecting!"
wait key
for i = 0 to CLIENTS-1
channels(i) = winsock connect(HOST_NAME, HOST_PORT)
if winsock channel error(channels(i))
print winsock channel error msg$(channels(i))
else
inc connected
endif
sync
next i
print "clients connected: " + str$(connected)
print "hit a key to continue."
wait key
data_ptr as DWORD
data_len as INTEGER
an_integer as INTEGER
correct = 0
incorrect = 0
while (not escapekey())
winsock refresh channels
for i=0 to connected-1
if (winsock channel data waiting(channels(i)))
winsock recv message channels(i)
if winsock channel error(channels(i))
`a channel error occurred (may be disconnection.)
else
data_ptr = winsock channel data ptr(channels(i))
data_len = winsock channel data len(channels(i))
if (data_len = 4)
an_integer = *data_ptr
if (an_integer = connected)
inc correct
else
inc incorrect
endif
else
if (data_len = 0)
`channel disconnected by server!
else
inc incorrect
endif
endif
endif
endif
next i
cls
set cursor 0,0
print "connections correct: " + str$(correct)
print "connections incorrect: " + str$(incorrect)
sync
endwhile
winsock clean up
server:
`SERVER
#constant CLIENT_AMOUNT 4000
#constant LOCAL_PORT 4321
set window on
winsock make
if winsock error()
print winsock error msg$()
wait key
end
endif
listen_channel as DWORD
dim channels(CLIENT_AMOUNT) as DWORD
listen_channel = winsock listen(LOCAL_PORT)
if winsock channel error(listen_channel)
print winsock channel error msg$(listen_channel)
wait key
end
endif
print "listening on port " + str$(LOCAL_PORT)
clients = 0
sent = 0
a_ptr as DWORD
a_ptr = make memory(4)
while (not Escapekey())
winsock refresh channel listen_channel
if (winsock channel data waiting(listen_channel))
channels(clients) = winsock accept(listen_channel)
inc clients
endif
set cursor 0, 0
cls
print "listening on port: " + str$(LOCAL_PORT)
print "clients connected: " + str$(clients)
if not sent
print "hit enter to send an integer to all clients"
if returnkey()
print "sending connection count to clients..."
*a_ptr = clients
time_start = timer()
for i=0 to clients-1
winsock send message channels(i), a_ptr, 4
next i
time_total = timer() - time_start
sent = 1
endif
else
print "sending took " + str$(time_total) + "ms"
endif
sync
endwhile
delete memory a_ptr
winsock clean up
Test it and tell me how many connections you can have! I get max. of 3970, the other 30 connection attempts fail. If you get 4000, try to increase the constant that defines the max CLIENT count at the beginning of both files!
Note: In the release version the sending time of the server will be even better than 1 sec for all 3970 cons!
-- I just started with DarkSDK, by translating DBP Projects. --