diff --git a/bitmap/buid.sh b/bitmap/buid.sh deleted file mode 100644 index e2164d8..0000000 --- a/bitmap/buid.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -gcc -o main main.c -./main \ No newline at end of file diff --git a/bitmap/build.sh b/bitmap/build.sh new file mode 100644 index 0000000..e2164d8 --- /dev/null +++ b/bitmap/build.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +gcc -o main main.c +./main \ No newline at end of file diff --git a/cp-Linux/buid.sh b/cp-Linux/buid.sh deleted file mode 100644 index 4cac8be..0000000 --- a/cp-Linux/buid.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -gcc -o main main.cpp -./main \ No newline at end of file diff --git a/cp-Linux/build.sh b/cp-Linux/build.sh new file mode 100644 index 0000000..4cac8be --- /dev/null +++ b/cp-Linux/build.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +gcc -o main main.cpp +./main \ No newline at end of file diff --git a/cp-homework/buid.sh b/cp-homework/buid.sh deleted file mode 100644 index 4cac8be..0000000 --- a/cp-homework/buid.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -gcc -o main main.cpp -./main \ No newline at end of file diff --git a/cp-homework/build.sh b/cp-homework/build.sh new file mode 100644 index 0000000..4cac8be --- /dev/null +++ b/cp-homework/build.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +gcc -o main main.cpp +./main \ No newline at end of file diff --git a/cp/buid.sh b/cp/buid.sh deleted file mode 100644 index 21798a7..0000000 --- a/cp/buid.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -gcc -o main main.cpp -./main test.txt test2.txt \ No newline at end of file diff --git a/cp/build.sh b/cp/build.sh new file mode 100644 index 0000000..21798a7 --- /dev/null +++ b/cp/build.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +gcc -o main main.cpp +./main test.txt test2.txt \ No newline at end of file diff --git a/ptypes-tcp/build.bat b/ptypes-tcp/build.bat new file mode 100644 index 0000000..c81b20e --- /dev/null +++ b/ptypes-tcp/build.bat @@ -0,0 +1,3 @@ +@echo off +call ../vcppbuild.bat client "/link /LIBPATH:../ext/libs ptypes.lib /SUBSYSTEM:CONSOLE" +call ../vcppbuild.bat server "/link /LIBPATH:../ext/libs" \ No newline at end of file diff --git a/ptypes-tcp/build.sh b/ptypes-tcp/build.sh new file mode 100644 index 0000000..15bfec9 --- /dev/null +++ b/ptypes-tcp/build.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +gcc -o client -lptypes client.cpp +gcc -o server -lptypes server.cpp diff --git a/ptypes-tcp/client.cpp b/ptypes-tcp/client.cpp new file mode 100644 index 0000000..abb6750 --- /dev/null +++ b/ptypes-tcp/client.cpp @@ -0,0 +1,35 @@ +#include +#include +#include + +#pragma comment(lib, "ptypes.lib") +#pragma comment(lib, "user32.lib") +#pragma comment(lib, "ws2_32.lib") + + +USING_PTYPES + +const int port = 8085; + +int main() +{ + ipstream client(ipaddress(127, 0, 0, 1), port); + + try + { + client.open(); + client.putline("Hello"); + client.flush(); + + string rsp = client.line(); + pout.putf("Received: %s\n", pconst(rsp)); + client.close(); + } + catch(estream* e) + { + perr.putf("Error: %s\n", pconst(e->get_message())); + delete e; + } + + return 0; +} \ No newline at end of file diff --git a/ptypes-tcp/server.cpp b/ptypes-tcp/server.cpp new file mode 100644 index 0000000..de7c688 --- /dev/null +++ b/ptypes-tcp/server.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include + +#pragma comment(lib, "ptypes.lib") +#pragma comment(lib, "user32.lib") +#pragma comment(lib, "ws2_32.lib") + +USING_PTYPES + +const int port = 8085; +const int maxtoken = 4096; + +void servermain(ipstmserver& svr) +{ + ipstream client; + + pout.putf("Ready to answer queries on port %d\n", port); + + while(true) + { + svr.serve(client); + if (client.get_active()) + { + try + { + string req = lowercase(client.line(maxtoken)); + if (req == "hello") + { + string host = phostbyaddr(client.get_ip()); + if (isempty(host)) + host = iptostring(client.get_ip()); + + client.putline("Hello, the current timestamp is - " + itostring(now())); + client.flush(); + + pout.putf("%t greeting received from %s (%a)\n", + now(), pconst(host), long(client.get_ip())); + } + + client.close(); + } + catch(estream* e) + { + perr.putf("Error: %s\n", pconst(e->get_message())); + delete e; + } + } + } +} + +int main() +{ + ipstmserver svr; + + try + { + svr.bindall(port); + + servermain(svr); + } + catch(estream* e) + { + perr.putf("FATAL: %s\n", pconst(e->get_message())); + delete e; + } + + return 0; +} \ No newline at end of file diff --git a/ptypes-threads/buid.sh b/ptypes-threads/buid.sh deleted file mode 100644 index 463751f..0000000 --- a/ptypes-threads/buid.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -gcc -o main -lptypes main.cpp -./main \ No newline at end of file diff --git a/ptypes-threads/build.bat b/ptypes-threads/build.bat index fc303b3..1735e29 100644 --- a/ptypes-threads/build.bat +++ b/ptypes-threads/build.bat @@ -1,7 +1,4 @@ @echo off -::pushd .. -::set parent=%cd% -::popd call ../vcppbuild.bat main "/link /LIBPATH:../ext/libs" main.exe pause \ No newline at end of file diff --git a/ptypes-threads/build.sh b/ptypes-threads/build.sh new file mode 100644 index 0000000..463751f --- /dev/null +++ b/ptypes-threads/build.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +gcc -o main -lptypes main.cpp +./main \ No newline at end of file diff --git a/ptypes-threads/main.cpp b/ptypes-threads/main.cpp index 63d4d10..71babaf 100644 --- a/ptypes-threads/main.cpp +++ b/ptypes-threads/main.cpp @@ -1,4 +1,4 @@ -#include +#include #include #pragma comment(lib, "../ext/libs/ptypes.lib") diff --git a/vcppbuild.bat b/vcppbuild.bat index cc28818..a948ee6 100644 --- a/vcppbuild.bat +++ b/vcppbuild.bat @@ -13,5 +13,5 @@ if exist "c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" ( goto compile ) :compile -cl.exe /clr /D WIN32 /I"..\ext\include" %1.cpp %2 +cl.exe /Zi /nologo /W3 /WX- /O2 /Ob1 /Oy- /D "_CONSOLE" /D "NDEBUG" /D "WIN32" /D "_VC80_UPGRADE=0x0600" /D "_MBCS" /GF /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /I"..\ext\include" %1.cpp %2 del %1.obj \ No newline at end of file