Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

masnu

@masnu
About
Posts
76
Topics
38
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Winsock problem
    M masnu

    No.. I had my embedded board connected to the PC with a cross-over cable.. no switch.

    C / C++ / MFC sysadmin help question

  • Winsock problem
    M masnu

    I can see how that would happen. Thankfully this one didn't take me that much time. Try WireShark http://www.wireshark.org/[^] it's a useful tool.

    C / C++ / MFC sysadmin help question

  • Winsock problem
    M masnu

    I was using Wireshark, but it DID display an incorrect checksum. I just got busy doing other things and completely overlooked it. It wasn't until I focused on the problem that I paid attention to what the analyzer was telling me.

    C / C++ / MFC sysadmin help question

  • Winsock problem
    M masnu

    Nope! It was a me problem!! :-) Thanks Moak!

    C / C++ / MFC sysadmin help question

  • Winsock problem
    M masnu

    For those of you who are interested I finally figured out what the problem was. When I implemented the TCP/IP stack on the micro I made a mistake in the routine that calculates the IP header checksum. With an invalid checksum Winsock just disregarded the message. Once the correct checksum was sent everything worked fine. Thanks to all of you for your help. I appreciate it. Paul

    C / C++ / MFC sysadmin help question

  • Winsock problem
    M masnu

    Sorry Moak, I was cutting and pasting and forgot the most important part. Here's the actual code to open and connect:

    int CHPCtrl::Connect()
    {

    struct sockaddr\_in	rmtAddr;
    

    // Create data socket
    m_Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

    if ( m\_Socket == INVALID\_SOCKET )
    	return 1;
    

    // Set client properties
    rmtAddr.sin_family = AF_INET;
    rmtAddr.sin_addr.s_addr = inet_addr( remoteIP );
    rmtAddr.sin_port = htons( m_nDevicePort );

    // Connect to remote
    if ( connect( m_Socket, (struct sockaddr *)&rmtAddr, sizeof(rmtAddr) ) == SOCKET_ERROR )
    return 1;

    // Open rx monitor thread
    m_hRxMonitor = (HANDLE)_beginthreadex( 0, 0, RxMonitor, this, CREATE_SUSPENDED, 0 );

    if ( m\_hRxMonitor )
    {
    	
    	m\_bConnected = true;
    	ResumeThread( m\_hRxMonitor );
    
    } //\_\_if ( m\_pReadThread )\_\_
    
    return 0;
    

    }

    And in a separate thread I wait for incoming data:

    UINT CHPCtrl::RxMonitor(void *pThis)
    {

    CHPCtrl		\*pCtrl = (CHPCtrl\*)pThis;
    int		bytes\_recevied = 0;
    
    fd\_set		sckt;
    timeval		timeout;
    

    // Set two second timeout
    timeout.tv_sec = 2;
    timeout.tv_usec = 0;

    // Monitor all rx traffic
    while ( pCtrl->m_bConnected )
    {

    	FD\_ZERO( &sckt );
    	FD\_SET( pCtrl->m\_Socket, &sckt );
    
    	int ret = select( 0, &sckt, 0, 0, &timeout );
    
    	switch ( ret )
    	{
    
    		case  SOCKET\_ERROR:
    			//Handle error 
    			break;
    
    		case 0:	//Timeout
    			//Handle time out
    			break;
    
    		default:
    			pCtrl->ReadFromSocket( pCtrl->m\_Socket );
    
    	} //\_\_switch ( ret )\_\_
    
    } //\_\_while ( m\_bRunRx )\_\_
    

    // Shutdown rx comm
    shutdown( pCtrl->m_Socket, SD_RECEIVE );

    return 0;
    

    }

    m_Socket is a class variable. I did this so I can send and receive on the same socket without blocking. Please let me know if you see anything wrong with this.

    C / C++ / MFC sysadmin help question

  • Winsock problem
    M masnu

    Please elaborate as to which part of the post wasn't in "international" English and I will be happy to clarify.

    C / C++ / MFC sysadmin help question

  • Winsock problem
    M masnu

    I'm not using any BSP and I implemented the TCP stack myself. I am able to establish communication via the 3-way handshaking process and then I assemble the package and send it. I used Wireshark to trap the packets between the PC and the micro and it recognizes it as a valid TCP/IP packet so I'm assuming it's formated properly.

    C / C++ / MFC sysadmin help question

  • Winsock problem
    M masnu

    Yes I can connect to the micro and send data from the PC to the micro but not the other way around. My socket is created as follows:

    // Create socket
    Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

    And then I wait for data:

    fd_set sckt;
    timeval timeout;

    // Set two second timeout
    timeout.tv_sec = 2;
    timeout.tv_usec = 0;

    FD_ZERO( &sckt );
    FD_SET( Socket, &sckt );

    int nRet = select( 0, &sckt, 0, 0, &timeout );

    select always returns 0 indicating a timeout no matter how much data I send from the micro.

    C / C++ / MFC sysadmin help question

  • Winsock problem
    M masnu

    Hi, I'm trying to enable my ARM development board to communicate with a PC. I can establish a connection and send data from the PC to the micro without any issues. When I try to send data from the micro to the PC, however, my socket doesn't respond to the data. A network analyzer shows that the packet was sent and formated properly. I have tried both TCP and UDP with the same results. Has anyone come across this before? Thanks.

    C / C++ / MFC sysadmin help question

  • VS2005 & VS2008 DLL Compilation issues
    M masnu

    Thanks Chris. I know what the /MD and /MT switches are for. What I don't understand is why the /MD switch would work on a machine with VS2005 only and not on the other.

    C / C++ / MFC question

  • VS2005 & VS2008 DLL Compilation issues
    M masnu

    Thanks but I have already installed the VC++ 2005 and 2008 runtime libraries on the target machine. That doesn't help, though. I am developing on a Windows 7 machine. Should that make a difference?

    C / C++ / MFC question

  • VS2005 & VS2008 DLL Compilation issues
    M masnu

    Hi guys, I have VS2005 and VS2008 installed on my development machine. Whenever I develop a DLL I have to link with the /MT (Multi-Threaded) option if I want to use it on any other machine. If I compile the DLL on a machine with VS2005 only, however, I don't have to use the /MT option, I can use the /MD (Multi-Threaded DLL) and the DLL can be used on any machine. Has anyone else come across this? Is there a way to resolve this? Thanks.

    C / C++ / MFC question

  • Exporting a struct from a DLL
    M masnu

    Hi guys, Is it possible to export a structure from a dll without including the header file where the structure is define? For example:

    /*-------------------------
    mydllheader.h
    ------------------------------*/

    extern "C" __declspec(dllexport) struct MyStruct
    {

     MyStruct()
     {
         a = 0;
         b = 0;
     }
    
     int a;
     int b;
    

    }

    Instead of including mydllheader.h I want to do the following:

    /*-------------------------
    myimportheader.h
    ------------------------------*/

    extern "C" __declspec(dllimport) struct MyStruct

    I would like to use myimportheader.h in my projects that use the dll that way I can hide my structure implementation from the user. Is that possible? Thanks.

    C / C++ / MFC tutorial question

  • How to get a thread's exit code
    M masnu

    Thanks Rajesh. I appreciate the help. Paul

    C / C++ / MFC question help tutorial

  • How to get a thread's exit code
    M masnu

    Hi Rajesh, I know that returning from a thread will call _endthreadex() but everything I have read says that "terminating a thread with a call to endthread or _endthreadex helps to ensure proper recovery of resources allocated for the thread". Is it safe to assume that returning will accomplish this? Thanks, Paul

    C / C++ / MFC question help tutorial

  • How to get a thread's exit code
    M masnu

    Hi guys, I'm creating a multi-threaded application using _beginthreadex() and _endthreadex(). If my thread executes correctly I call _endthreadex( 0 ) but if it doesn't I call _endthreadex( _<some error code>_ ). How can I capture the thread's exit code in the main thread? Thanks.

    C / C++ / MFC question help tutorial

  • Simple menu question
    M masnu

    I need to update the check on my menu item so created a message handler to my UPDATE_COMMAND_UI event. The code is as follows:

    void CSpDlg::OnUpdateShowPeak(CCmdUI *pCmdUI)
    {

    // Update menu
    pCmdUI->SetCheck( m_bShowPeakVoltage );

    }

    The menu item does not update, however. I'm I missing something? Thanks.

    C / C++ / MFC question announcement

  • Getting Thread Exit Code
    M masnu

    The exit code I want is the one I have defined as nError in the above example. Based on that number I can determine why the thread exited.

    C / C++ / MFC sysadmin help question

  • Getting Thread Exit Code
    M masnu

    I have created a worker thread to connect to a data server. The thread needs to wait a few seconds and exit if no data arrives (i.e. server is not online). I need to trap the thread exit code so my main thread can know if the workher thread terminated with an error. I have the following code: static UINT Connect(void* p_this); UINT Connect(); UINT Client::Connect(void* p_this) { Client* pClient = (Client*)p_this; pClient->Connect(); } UINT Client::Connect() { CDataServer pServer = new CDataServer(); ........ int nError = pServer->Connect(); if ( nError != 0 ) //Error connecting to server return nError; ....... } From the documentation I know I can use GetExitCodeThread to get the error code but where is the best place to put this? Should I post an exit message to the main thread and read the code there? Are there any other solutions that would be better? Thanks.

    C / C++ / MFC sysadmin help question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups