We help IT Professionals succeed at work.

CSocket / CArchive

Triskelion asked
I have created an application and am trying to make it log into a Unix box with a standard user name and password.

I have replicated most of the "Chatter" code (from the samples) and the project compiles fine.  The biggest change I made is that I pipe everything into the View class instead of the Doc class.

The problem comes when the app is calling Serialize.
It hangs until I get the message:
"An attempt was made to access an unnamed file past its end.

The response I get from the server is bunch of strange characters (14) and nothing else.

The only data type I use for retrieving is  a CString.

What should I be receiving?
Watch Question


Can u post the code that u have written.


MRN Murthy


It's too much code.
You know how MSVC creates modules.
In all practicality, the Socket *is* 'chatter'.
If you have that sample, change the section where the port is added to (value) 700 and make it connect to something you know has telnet turned on.
The question is, "what should you see?".


...and before you ask...
Yes, it communicates with 'ChatSrvr' very well.


Should the archive method cause a problem since it passes a CString?  Does it matter?

Here is the serialize code from the chatter:
void CMsg::Serialize(CArchive& ar)
     if (ar.IsStoring())
          ar << (WORD)m_bClose;
          ar << m_strText; //CString
          WORD wd;
          ar >> wd;
          m_bClose = (BOOL)wd;
          ar >> m_strText;
I wouldn't send a CString to a a non-MFC host - because when CString serializes it prepends its size before the text

eg the CString of 'Hello' would be something like


send what the protocol would expect to see


Then (in an attempt to normalize this) would you:
   A) abandon the archive
   B) use Write() or WriteString() instead of "<<"
   C) Do something else?

>>send what the protocol would expect to see
   What? A character array?
   How would this work with the "<<" or does it?
> I have created an application and am trying to make it log into a Unix box with a standard user name and password.

what sort of login? - what is the server expecting to see in the packets? eg format - what will its response be? - what is the protocol?

A) no just don't use MFC specific classes eg CString - keep it to simple types eg short/long/char(arrays - ANSI not UNICODE) - you can use the socket methods directly if you wish (Send/Receive) its what the Archive/file uses anyway in the end

B) up to you '<<' is not the problem

C) learn about sockets - eg if sending longs/shorts use htohs,htons etc as UNIX and PCs usually have different endian-ness (PCs are little endian) - these functions use network order - so if everyone puts data in netork order and does the approprite conversions (using the functions/macros) all is well (easier)


The protocol is TCP/IP

The login is a standard unix text-based telnet user-login.

I'm not collaborating with packets, I'm attempting to read the login prompt and respond to it.
> The protocol is TCP/IP

that is the netork protocol -

> telnet user-login

ah now thats more like it - okay have you looked at the RFC specification of telnet ?

if not have a look at it


and then we can walk through it step by step - I dont have access to a unix box - but that isn't important as I should be able to use any old telnet server (and so could you)


At first glance, this looks promising.
While I'm not at work, I test the connection with a local college's unix box.  I just kept hacking around with names until I got a prompt.  :-)

Let me look at this RFC.


Man, I've got a lot to digest.
BTW, here's a nice list of places to test for telnet connections.

Maybe I need to see if there's a Telnet object library floating around the web somewhere.


Thanks!  I'll try it.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.