Source Code - dpp/source/winsock server.dpp
Download link (right click, save as)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
|
function main()
{
title "SimpleServer";
winsock server;
listen();
}
function listen()
{
newvar port=500,state;
sock[server].listen(port);
call AddText("Info> Listening on port "& port & "...");
}
function server_close()
{
sock[server].Close();
call AddText("Info> Closed.");
call listen();
}
function server_request(requestID)
{
newvar remote;
sock[server].close();
sock[server].accept(requestID);
sock[server].getinfo("remoteip", remote);
call AddText("Info> Connection request from " & remote & ".");
call AddText("Info> Connection accepted.");
call SendData("Hello! Welcome to SimpleServer!");
}
function server_incoming(data, bytesTotal)
{
call AddText("Client> " & Data);
if lcase(left(Data, 5)) = "echo " then
call SendData(Mid(Data, 6));
elseif lcase(data) = "vb.net" then
call SendData("VB.NET? You disgust me.");
elseif lcase(data) = "bl" then
call SendData("Ho yeah, gonna rock your world!");
elseif lcase(data) = "about" then
call SendData("SimpleServer v1.0. D++ FOREVER!");
elseif lcase(data) = "count" then
newvar i;
call SendData("Counting...");
pause .5;
for i = 1 to 5;
call SendData(i);
pause .5;
next i;
endif
}
function server_error(number, description)
{
call AddText("Error> " & err.Description);
call sock_Close();
}
function AddText(text)
{
screenput text; screen;
}
function SendData(data)
{
sock[server].Send(Data);
call AddText("Server> " & Data);
doevents;
}
|
This code is Copyright (C) 2000-2012 PageMac Programming. Reproduction of this code must adhere to the GNU General Public License.