Re: Newcomer's CAsyncSocket example: trouble connecting with other clients



stephen park wrote:

Wow, I really hate turning this into a .net discussion in an mfc
group, but I built a CLR console app and this just doesn't send
anything to the Newcomer server: (code in its entirety)

#include "stdafx.h"

using namespace System;
using namespace System::Net::Sockets;


int main(array<System::String ^> ^args)
{
TcpClient^ c = gcnew TcpClient( server,port );
String^ msg = "hello, world!";
array<Byte>^data = Text::Encoding::ASCII->GetBytes( msg );
c->Client->Send( data );

Console::ReadKey();

c->Close();

return 0;
}

The server says its connected, but when I hit a key the server says
?.?.?.? [?] Closed

with the "Last Received Message" edit box empty.

Doing the same thing with csocket and an mfc console app does the same
thing. Just what the heck am I missing in both?


I don't know what Joe's program is, but the above is correct when you
are talking to a telnet-like like server. I have no reason to question Joe's CAsyncServer, but I have not try it to see what it suppose to do for you.

What part are you trying to make work? What are you looking for?

What I would do is begin with the basics of writing a TTY client. If you are just learning sockets, you need to begin with the
basics, which comes with "mistakes" and trial and error process.

Try this TTY() function:

void tty(String ^hostname, int port)
{

Console::WriteLine("* Connecting");

TcpClient^ c;

try {
c = gcnew TcpClient(hostname,port);
} catch(SocketException ^e) {
Console::WriteLine(L"- Connect Error {0}",e->ErrorCode);
Console::ReadKey();
return;
}

// use 100ms timeout for reader
c->Client->ReceiveTimeout = 100;

array<Byte>^ bytes = gcnew array<Byte>(1024);
NetworkStream ^cio = c->GetStream();

while (1) {
if (Console::KeyAvailable) {
ConsoleKeyInfo^ key = Console::ReadKey(true);
if (key->Key == ConsoleKey::Escape) break;
try {
cio->WriteByte(key->KeyChar);
} catch( Exception ^e) {
break;
}
}
try {
int nBytes = c->Client->Receive( bytes );
for (int i=0; i < nBytes; i++) {
Console::Write("{0}",(wchar_t)bytes[i]);
}
} catch( SocketException ^e) {
if (e->ErrorCode == 10054) {
Console::WriteLine(L"! Disconnect");
break;
}
}
}
c->Close();
Console::WriteLine("* Closed");
Console::ReadKey();
}


You can try this against any TELNET like server, including any TELNET, SMTP, FTP, NNTP, POP3, IMAP server, etc.

Here are a few telnet servers:

bbs.winserver.com port=23
beta.winserver.com port=23

Even SMTP, FTP or NNTP servers, try these:

msforums.winserver.com port=119
news.microsoft.com port119

You know, you can make the tty() function a SERVER by changing the connect() which you are implicitly doing with the constructor

gcnew TcpClient(hostname,port)

above and replacing it with SOCKET functional calls equivalent in C/C++.NET for:

Listen()
Bind()
Accept()

Anyway, if your question is about your code, it is fine. I don't know Joe's code but I'm sure it works. :)

--
.



Relevant Pages

  • Re: inetd to take telnet request
    ... flavours of TELNET here - so I read on. ... I know about INETD only from long ago with the RS/6000 UNIX, ... server applications" in the CS IP Configuration Guide: ...
    (bit.listserv.ibm-main)
  • Re: Product for Running Embedded C# Application
    ... Telnet sessions or Web sessions with our Web server on the device and a lot ... There's a Telnet server available to Windows CE ... communicates with specific hardware and forwards data to a back end ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: RDP access to SBS 2003 - HELP please
    ... Might I add that 'out of the box', when I first got the server it worked ... of it to the telnet prompt and quit. ... Try the remote desktop connection to see if it works. ... the effect that it can't connect to xxx.xxx.xxx.xxx port 23. ...
    (microsoft.public.windows.server.sbs)
  • Re: Telnet session "Shell process may not have been launched" (Solution)
    ... this is a feature change in win2k3 server. ... Microsoft Online Partner Support ... >the 2003 Security Guide suggests you disable the service, ... but Telnet won't be functional without it. ...
    (microsoft.public.windows.server.general)
  • RE: Your message did not reach some or all of the intended recipie
    ... In your details you are saying to type the following command ... > SMTP telnet session. ... When the issue happens again, in the Exchange Server, please telnet ... > times to close the connection to the server and leave the Telnet session ...
    (microsoft.public.windows.server.sbs)