-
WinSock
From
Jon Justvig@VERT/STEPPING to
All on Sat Jun 9 13:29:33 2018
Hi all...ããI am looking for examples of how to create a WinSock server. I would like forãa telnet client to connect to the server. The server first displays text andãprovides a prompt for user input from the client. Can someone guide me in theãright direction or provide a piece of code I can work with? I've googled untilãmy guts fall out. I am building on a Win32 platform using Visual C++ StudioãCommunity 2017.ããThanks in advance.ããSincerely,ãJon JustvigãStepping Stone BBSã
telnet://vintagebbsing.com:2325ãhttp://vintagebbsing.com:8085ãã---ã þ Synchronet þ Stepping Stone BBS - vintagebbsing.com:2325ã
-
From
Digital Man@VERT to
Jon Justvig on Sat Jun 9 20:08:31 2018
Re: WinSockã By: Jon Justvig to All on Sat Jun 09 2018 01:29 pmãã > Hi all...ã >ã > I am looking for examples of how to create a WinSock server. I would likeã > for a telnet client to connect to the server. The server first displaysã > text and provides a prompt for user input from the client. Can someoneã > guide me in the right direction or provide a piece of code I can work with?ã > I've googled until my guts fall out. I am building on a Win32 platformã > using Visual C++ Studio Community 2017.ããHere's a sample:ãã
https://www.tutorialspoint.com/unix_sockets/socket_server_example.htmããIt's generic socket example, but it's mostly relevant to WinSock. With Windowsã(and WinSock) you can't treat socket handles as file descriptors, so you'llãhave to replace the call to read() with recv() and replace write() with send().ããThere's a similar WinSock-specific example on this page from Microsoft:ã
https://msdn.microsoft.com/en-us/library/windows/desktop/ms740149(v=vs.85).aspxãã digital manããThis Is Spinal Tap quote #40:ãMorty the Mime: Come on, don't talk back, mime is money, come on, move it.ãNorco, CA WX: 73.2øF, 52.0% humidity, 10 mph ENE wind, 0.00 inches rain/24hrsã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
-
From
Jon Justvig@VERT/STEPPING to
Digital Man on Mon Jun 11 01:33:56 2018
Re: WinSockã By: Digital Man to Jon Justvig on Sat Jun 09 2018 08:08 pmããHere's my code, trying to output using a socket:ããchar c;ãstd::fstream myStream("welcome.txt", std::fstream::in);ãwhile (myStream.get(c))ã{ããsend(clientSocket, (const char*)c, size_t(0), 0);ã std::cout << c;ããOf course it outputs fine on the console, yet, it doesn't start on the secondãline on column 1, it starts the second line on the line above and on the columnãif left on...ããSincerely,ãJon JustvigãStepping Stone BBSã
telnet://vintagebbsing.com:2325ãhttp://vintagebbsing.com:81ãã---ã þ Synchronet þ Stepping Stone BBS - vintagebbsing.com:2325ã
-
From
Nightfox@VERT/DIGDIST to
Jon Justvig on Mon Jun 11 10:00:12 2018
Re: WinSockã By: Jon Justvig to Digital Man on Mon Jun 11 2018 01:33 amãã JJ> Here's my code, trying to output using a socket:ãã JJ> char c;ã JJ> std::fstream myStream("welcome.txt", std::fstream::in);ã JJ> while (myStream.get(c))ã JJ> {ãã JJ> send(clientSocket, (const char*)c, size_t(0), 0);ã JJ> std::cout << c;ããWhere/how is clientSocket declared? And has it been set up with a valid socketãhandle? That isn't shown in your code snippet. It looks like this code isãreading from a text file and trying to send each character from the file over aãsocket?ããAlso, did you intend for the "std::cout << c" to be indented? It doesn't needãto be, as it's not in a separate block of code.ããNightfoxãã---ã þ Synchronet þ Digital Distortion: digitaldistortionbbs.comã
-
From
Jon Justvig@VERT/STEPPING to
Nightfox on Mon Jun 11 17:56:10 2018
Re: WinSockã By: Nightfox to Jon Justvig on Mon Jun 11 2018 10:00 amãã JJ>> Here's my code, trying to output using a socket:ãã JJ>> char c;ã JJ>> std::fstream myStream("welcome.txt", std::fstream::in);ã JJ>> while (myStream.get(c))ã JJ>> {ãã JJ>> send(clientSocket, (const char*)c, size_t(0), 0);ã JJ>> std::cout << c;ãã Ni> Where/how is clientSocket declared? And has it been set up with a validã Ni> socket handle? That isn't shown in your code snippet. It looks like thisã Ni> code is reading from a text file and trying to send each character fromã Ni> the file over a socket?ããSOCKET clientSocket = accept(listening, (sockaddr*)&client, &clientSize);ããI intend to read a text file and have it sent to the client through the socket.ãã Ni> Also, did you intend for the "std::cout << c" to be indented? It doesn'tã Ni> need to be, as it's not in a separate block of code.ããIndentations has no meaning in source code except cosmetically.ããSincerely,ãJon JustvigãStepping Stone BBSã
telnet://vintagebbsing.com:2325ãhttp://vintagebbsing.com:81ãã---ã þ Synchronet þ Stepping Stone BBS - vintagebbsing.com:2325ã
-
From
Jon Justvig@VERT/STEPPING to
Digital Man on Tue Jun 12 01:13:59 2018
Re: WinSockã By: Digital Man to Jon Justvig on Sat Jun 09 2018 08:08 pmããDM,ããOkay, I figured out send() just fine. I'm having major issues with recv(). ãRight now, I can only get it to input one character, even with char arrays orãstrings. Here's a sample: ããint result;ãã// our recv loopãwhile (true)ã{ããresult = recv(current_client, buffer, sizeof(buffer), 0); // recv cmdsããSleep(10);ããif (result > 0)ã{ãcout << "\n\tMessage from client: " << buffer;ãsend(current_client, (const char*)buffer, sizeof(buffer), 0);ã}ããSincerely,ãJon JustvigãStepping Stone BBSã
telnet://vintagebbsing.com:2325ãhttp://vintagebbsing.com:81ãã---ã þ Synchronet þ Stepping Stone BBS - vintagebbsing.com:2325ã
-
From
Nightfox@VERT/DIGDIST to
Jon Justvig on Tue Jun 12 09:26:35 2018
Re: WinSockã By: Jon Justvig to Nightfox on Mon Jun 11 2018 05:56 pmãã JJ> Indentations has no meaning in source code except cosmetically.ããYes, but indentations in C/C++ are typically done for separate code blocks. Ifãyou indent code randomly, then it is more difficult to read.ããNightfoxãã---ã þ Synchronet þ Digital Distortion: digitaldistortionbbs.comã
-
From
Digital Man@VERT to
Jon Justvig on Tue Jun 12 11:32:06 2018
Re: WinSockã By: Jon Justvig to Digital Man on Tue Jun 12 2018 01:13 amãã > Re: WinSockã > By: Digital Man to Jon Justvig on Sat Jun 09 2018 08:08 pmã >ã > DM,ã >ã > Okay, I figured out send() just fine. I'm having major issues with recv().ã > Right now, I can only get it to input one character, even with char arraysã > or strings. Here's a sample:ã >ã > int result;ã >ã > // our recv loopã > while (true)ã > {ã >ã > result = recv(current_client, buffer, sizeof(buffer), 0); // recv cmdsã >ã > Sleep(10);ã >ã > if (result > 0)ã > {ã > cout << "\n\tMessage from client: " << buffer;ã > send(current_client, (const char*)buffer, sizeof(buffer), 0);ã > }ããWhere is the definition of 'buffer'?ãã digital manããSynchronet "Real Fact" #75:ãRob's alias "digital man" was inspired by a song on Rush's 1982 "Signals" album.ãNorco, CA WX: 82.9øF, 38.0% humidity, 8 mph NNE wind, 0.00 inches rain/24hrsã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
-
From
Jon Justvig@VERT/STEPPING to
Digital Man on Tue Jun 12 16:34:12 2018
Re: WinSockã By: Digital Man to Jon Justvig on Tue Jun 12 2018 11:32 amãã >> Okay, I figured out send() just fine. I'm having major issues withã >> recv(). Right now, I can only get it to input one character, even withã >> char arrays or strings. Here's a sample:ããchar buffer[20];ãã >> int result;ãã >> // our recv loopã >> while (true)ã >> {ãã >> result = recv(current_client, buffer, sizeof(buffer), 0); // recv cmdsãã >> Sleep(10);ãã >> if (result > 0)ã >> {ã >> cout << "\n\tMessage from client: " << buffer;ã >> send(current_client, (const char*)buffer, sizeof(buffer), 0);ã >> }ããjust above int result; ...ããSincerely,ãJon JustvigãStepping Stone BBSã
telnet://vintagebbsing.com:2325ãhttp://vintagebbsing.com:81ãã---ã þ Synchronet þ Stepping Stone BBS - vintagebbsing.com:2325ã
-
From
Digital Man@VERT to
Jon Justvig on Tue Jun 12 17:29:46 2018
Re: WinSockã By: Jon Justvig to Digital Man on Tue Jun 12 2018 04:34 pmãã > Re: WinSockã > By: Digital Man to Jon Justvig on Tue Jun 12 2018 11:32 amã >ã > >> Okay, I figured out send() just fine. I'm having major issues withã > >> recv(). Right now, I can only get it to input one character, even withã > >> char arrays or strings. Here's a sample:ã >ã > char buffer[20];ã >ã > >> int result;ã >ã > >> // our recv loopã > >> while (true)ã > >> {ã >ã > >> result = recv(current_client, buffer, sizeof(buffer), 0); // recv cmdsã >ã > >> Sleep(10);ã >ã > >> if (result > 0)ã > >> {ã > >> cout << "\n\tMessage from client: " << buffer;ã > >> send(current_client, (const char*)buffer, sizeof(buffer), 0);ã > >> }ã >ã > just above int result; ...ããSo.. if you only receive 2 bytes (result == 2), you're still going to send 20ã(sizeof buffer)? That's probably not what you want.ãã digital manããThis Is Spinal Tap quote #16:ãDavid St. Hubbins: I believe virtually everything I read...ãNorco, CA WX: 83.2øF, 43.0% humidity, 9 mph ENE wind, 0.00 inches rain/24hrsã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
-
From
Jon Justvig@VERT/STEPPING to
Nightfox on Tue Jun 12 18:23:33 2018
Re: WinSockã By: Nightfox to Jon Justvig on Tue Jun 12 2018 09:26 amãã JJ>> Indentations has no meaning in source code except cosmetically.ãã Ni> Yes, but indentations in C/C++ are typically done for separate codeã Ni> blocks. If you indent code randomly, then it is more difficult to read.ããNormally, I use good indentations for functions and code inside like while orãdo loops, etc... The code I posted isn't difficult to read. I understand if itãwere more complex then I could understand you pointing it out. Anyway, I'mãmore interested in getting the code working... :|ããSincerely,ãJon JustvigãStepping Stone BBSã
telnet://vintagebbsing.com:2325ãhttp://vintagebbsing.com:81ãã---ã þ Synchronet þ Stepping Stone BBS - vintagebbsing.com:2325ã
-
From
MRO@VERT/BBSESINF to
Nightfox on Tue Jun 12 21:33:48 2018
Re: WinSockã By: Nightfox to Jon Justvig on Tue Jun 12 2018 09:26 amãã > Re: WinSockã > By: Jon Justvig to Nightfox on Mon Jun 11 2018 05:56 pmãã > JJ> Indentations has no meaning in source code except cosmetically.ãã > Yes, but indentations in C/C++ are typically done for separate code blocks.ã > If you indent code randomly, then it is more difficult to read.ãã > NightfoxãããINDENTATIONS ARE FOR POOFSãCARRIAGE RETURNS ARE WHERE IT'S ATã---ã þ Synchronet þ ::: BBSES.info - free BBS services :::ã
-
From
Jon Justvig@VERT/STEPPING to
Digital Man on Wed Jun 13 04:29:22 2018
Re: WinSockã By: Digital Man to Jon Justvig on Tue Jun 12 2018 05:29 pmãã >> char buffer[20];ãã > >>> int result;ãã > >>> // our recv loopã > >>> while (true)ã > >>> {ãã > >>> result = recv(current_client, buffer, sizeof(buffer), 0); // recvã > >>> cmds ãã > >>> Sleep(10);ãã > >>> if (result > 0)ã > >>> {ã > >>> cout << "\n\tMessage from client: " << buffer;ã > >>> send(current_client, (const char*)buffer, sizeof(buffer), 0);ã > >>> }ãã> just above int result; ...ãã DM> So.. if you only receive 2 bytes (result == 2), you're still going to sendã DM> 20 (sizeof buffer)? That's probably not what you want.ããHow might I receive between 2 and 12 bytes?ããSincerely,ãJon JustvigãStepping Stone BBSã
telnet://vintagebbsing.com:2325ãhttp://vintagebbsing.com:81ãã---ã þ Synchronet þ Stepping Stone BBS - vintagebbsing.com:2325ã
-
From
Digital Man@VERT to
Jon Justvig on Wed Jun 13 12:24:03 2018
Re: WinSockã By: Jon Justvig to Digital Man on Wed Jun 13 2018 04:29 amãã > Re: WinSockã > By: Digital Man to Jon Justvig on Tue Jun 12 2018 05:29 pmã >ã > >> char buffer[20];ã >ã > > >>> int result;ã >ã > > >>> // our recv loopã > > >>> while (true)ã > > >>> {ã >ã > > >>> result = recv(current_client, buffer, sizeof(buffer), 0); // recvã > > >>> cmdsã >ã > > >>> Sleep(10);ã >ã > > >>> if (result > 0)ã > > >>> {ã > > >>> cout << "\n\tMessage from client: " << buffer;ã > > >>> send(current_client, (const char*)buffer, sizeof(buffer), 0);ã > > >>> }ã >ã > > just above int result; ...ã >ã > DM> So.. if you only receive 2 bytes (result == 2), you're still going toã > DM> send 20 (sizeof buffer)? That's probably not what you want.ã >ã > How might I receive between 2 and 12 bytes?ããYou're calling recv() with a max-length of 20 (sizeof buffer). That doesn'tãmean you'll necessarily receive exactly 20 bytes. You could receive anywhereãbetween 0 and 20 bytes - the return value of recv() tells you how many bytesãyou received, if any.ãã digital manããThis Is Spinal Tap quote #7:ãNigel Tufnel: That's just nitpicking, isn't it?ãNorco, CA WX: 87.0øF, 41.0% humidity, 5 mph NE wind, 0.00 inches rain/24hrsã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
-
From
Jon Justvig@VERT/STEPPING to
Digital Man on Wed Jun 13 19:34:16 2018
Re: WinSockã By: Digital Man to Jon Justvig on Wed Jun 13 2018 12:24 pmããSOCKET current_client = (SOCKET)lpParam;ãã// buffer to hold our recived dataãchar buffer;ã// buffer to hold our sent dataãchar sendData[20];ã// for error checking ãint result;ãã// our recv loopãwhile (true)ã{ããresult = recv(current_client, (char*)&buffer, 1, 0); // recv cmdsããSleep(10);ããif (result > 0)ã{ãcout << "\n\tMessage from client: " << buffer;ãsend(current_client, (char*)&buffer, 1, 0);ã}ã}ã}ããRight now, it works, however, on the client side it only shows one character atãat time with Message from client: (character the remote end sent) ...I triedãusing a char array, however, it was just showing back garbage. How might I getãinput up to about 12 characters until the "\r" (carriage return) is received toãthe server from the remote client?ããSincerely,ãJon JustvigãStepping Stone BBSã
telnet://vintagebbsing.com:2325ãhttp://vintagebbsing.com:81ãã---ã þ Synchronet þ Stepping Stone BBS - vintagebbsing.com:2325ã
-
From
Digital Man@VERT to
Jon Justvig on Wed Jun 13 20:50:06 2018
Re: WinSockã By: Jon Justvig to Digital Man on Wed Jun 13 2018 07:34 pmãã > Re: WinSockã > By: Digital Man to Jon Justvig on Wed Jun 13 2018 12:24 pmã >ã > SOCKET current_client = (SOCKET)lpParam;ã >ã > // buffer to hold our recived dataã > char buffer;ã > // buffer to hold our sent dataã > char sendData[20];ã > // for error checkingã > int result;ã >ã > // our recv loopã > while (true)ã > {ã >ã > result = recv(current_client, (char*)&buffer, 1, 0); // recv cmdsã >ã > Sleep(10);ããThat Sleep() call shouldn't be necessary - just for debugging use?ãã > if (result > 0)ã > {ã > cout << "\n\tMessage from client: " << buffer;ã > send(current_client, (char*)&buffer, 1, 0);ã > }ã > }ã > }ã >ã > Right now, it works, however, on the client side it only shows one characterã > at at time with Message from client: (character the remote end sent) ...Iã > tried using a char array, however, it was just showing back garbage. Howã > might I get input up to about 12 characters until the "\r" (carriage return)ã > is received to the server from the remote client?ããSee sockreadline() inã
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/src/sbbs3/mailsrvr.c?revision=1.621ããIt's recv()'s one byte at a time a builds up the string until a \n is received.ãYou could easily adapt that to terminate on \r instead.ããI purposely pointed you to an old revision that doesn't support TLS, becauseãthe implementation is more simple.ãã digital manããThis Is Spinal Tap quote #7:ãNigel Tufnel: That's just nitpicking, isn't it?ãNorco, CA WX: 74.6øF, 51.0% humidity, 0 mph S wind, 0.00 inches rain/24hrsã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã