Click here to Skip to main content
15,924,507 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: UuidCreate return status Pin
DevMentor.org27-Jul-07 8:10
DevMentor.org27-Jul-07 8:10 
AnswerRe: UuidCreate return status Pin
Mark Salsbery27-Jul-07 8:52
Mark Salsbery27-Jul-07 8:52 
AnswerRe: UuidCreate return status Pin
Michael Dunn27-Jul-07 10:00
sitebuilderMichael Dunn27-Jul-07 10:00 
QuestionAbout Key board Message [modified] Pin
Max++27-Jul-07 6:27
Max++27-Jul-07 6:27 
AnswerRe: About Key board Message Pin
Eytukan27-Jul-07 7:05
Eytukan27-Jul-07 7:05 
GeneralRe: About Key board Message Pin
Max++27-Jul-07 7:19
Max++27-Jul-07 7:19 
GeneralRe: About Key board Message Pin
codemunkeh27-Jul-07 16:20
codemunkeh27-Jul-07 16:20 
QuestionWifi And Winsock2 Pin
djin9427-Jul-07 4:46
djin9427-Jul-07 4:46 
Hi Everybody.

I am currently trying to establish a connection between two computer linked with a Wifi network (ad hoc network). For that I tried to use Winsock2 but it didn't work as well as when I use it with LAN.

Could somebody help me please?

Thanks in advance.



Here is the code implemented for the server


// IAMNet.cpp : définit le point d'entrée pour l'application console.<br />
//<br />
<br />
#include "stdafx.h"<br />
#include "IAMNet.h"<br />
#include <winsock2.h><br />
#pragma comment(lib, "ws2_32.lib")<br />
<br />
<br />
#ifdef _DEBUG<br />
#define new DEBUG_NEW<br />
#endif<br />
<br />
<br />
// Seul et unique objet application<br />
<br />
CWinApp theApp;<br />
<br />
using namespace std;<br />
<br />
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])<br />
{<br />
    int nRetCode = 0;<br />
<br />
    // Initialise MFC et affiche un message d'erreur en cas d'échec<br />
    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))<br />
    {<br />
        // TODO : modifiez le code d'erreur selon les besoins<br />
        _tprintf(_T("Erreur irrécupérable : l'initialisation MFC a échoué\n"));<br />
        nRetCode = 1;<br />
    }<br />
    else<br />
    {<br />
        // TODO : codez le comportement de l'application à cet emplacement.<br />
        WSADATA WSAData;<br />
        SOCKET sock;<br />
        SOCKADDR_IN clientsin;<br />
        SOCKET csock;<br />
        SOCKADDR_IN sin;<br />
        SOCKADDR_IN csin;<br />
        CHAR buff;<br />
        WSAStartup(MAKEWORD(2,0), &WSAData);<br />
<br />
        cout<<"hello\n\r";<br />
<br />
        sin.sin_addr.s_addr    = INADDR_ANY;<br />
        sin.sin_family        = AF_INET;<br />
        sin.sin_port        = htons(50014);<br />
        sock = socket(AF_INET,SOCK_STREAM,0);<br />
        bind(sock, (SOCKADDR *)&sin, sizeof(sin));<br />
        gethostname(&buff, sizeof(buff));<br />
        listen(sock, 0);<br />
       <br />
        int val = 0;<br />
<br />
        while(1)<br />
        {<br />
            int sinsize = sizeof(csin);<br />
            if((csock = accept(sock, (SOCKADDR *)&csin, &sinsize)) != INVALID_SOCKET)<br />
            {<br />
               <br />
                int size = sizeof(clientsin);<br />
                int succes = getpeername(csock,(SOCKADDR *)&clientsin, &size);<br />
                int a = WSAGetLastError();<br />
               <br />
                send(csock, "Hello world!\r\n", 30, 0);<br />
                cout<<"client connected \n\r";<br />
            }<br />
        }<br />
}<br />
<br />
    return nRetCode;}<br />
<br />
}



Here is the code implemented for the client


// iamclient.cpp : définit le point d'entrée pour l'application console.<br />
<br />
//<br />
<br />
#include "stdafx.h"<br />
#include "iamclient.h"<br />
#include <winsock2.h><br />
#pragma comment(lib, "ws2_32.lib")<br />
<br />
<br />
#ifdef _DEBUG<br />
#define new DEBUG_NEW<br />
#endif<br />
<br />
<br />
// Seul et unique objet application<br />
<br />
CWinApp theApp;<br />
<br />
using namespace std;<br />
<br />
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])<br />
{<br />
    int nRetCode = 0;<br />
<br />
    // Initialise MFC et affiche un message d'erreur en cas d'échec<br />
    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))<br />
    {<br />
        // TODO : modifiez le code d'erreur selon les besoins<br />
        _tprintf(_T("Erreur irrécupérable : l'initialisation MFC a échoué\n"));<br />
        nRetCode = 1;<br />
    }<br />
    else<br />
    {<br />
        // TODO : codez le comportement de l'application à cet emplacement.<br />
        WSADATA WSAData;<br />
        WSAStartup(MAKEWORD(2,0), &WSAData);       <br />
        SOCKET sock;<br />
        SOCKADDR_IN sin;<br />
        char *buff = new char[255];<br />
        sin.sin_addr.s_addr    = inet_addr("180.0.0.2");<br />
        sin.sin_family        = AF_INET;<br />
        sin.sin_port        = htons(4148);<br />
        sock = socket(AF_INET,SOCK_STREAM,0);<br />
        bind(sock, (SOCKADDR *)&sin, sizeof(sin));<br />
        connect(sock, (SOCKADDR *)&sin, sizeof(sin));<br />
        while(1)<br />
        {<br />
            recv(sock, buff, sizeof(buff),0);<br />
            cout<<buff;<br />
        }<br />
    }<br />
<br />
    return nRetCode;<br />
}





djin94
AnswerRe: Wifi And Winsock2 Pin
Rage27-Jul-07 5:20
professionalRage27-Jul-07 5:20 
QuestionRe: Wifi And Winsock2 Pin
Mark Salsbery27-Jul-07 5:20
Mark Salsbery27-Jul-07 5:20 
AnswerRe: Wifi And Winsock2 Pin
led mike27-Jul-07 5:37
led mike27-Jul-07 5:37 
AnswerRe: Wifi And Winsock2 Pin
djin9429-Jul-07 23:30
djin9429-Jul-07 23:30 
AnswerRe: Wifi And Winsock2 Pin
Eytukan27-Jul-07 7:08
Eytukan27-Jul-07 7:08 
QuestionAnyone to help me? Pin
garfaoui27-Jul-07 4:42
garfaoui27-Jul-07 4:42 
AnswerRe: Anyone to help me? Pin
Cyrilix27-Jul-07 4:49
Cyrilix27-Jul-07 4:49 
GeneralRe: Anyone to help me? Pin
garfaoui27-Jul-07 4:50
garfaoui27-Jul-07 4:50 
GeneralRe: Anyone to help me? Pin
Rage27-Jul-07 5:22
professionalRage27-Jul-07 5:22 
AnswerRe: Anyone to help me? Pin
Rage27-Jul-07 5:40
professionalRage27-Jul-07 5:40 
GeneralRe: Anyone to help me? Pin
garfaoui29-Jul-07 22:40
garfaoui29-Jul-07 22:40 
AnswerRe: Anyone to help me? Pin
Eytukan27-Jul-07 7:14
Eytukan27-Jul-07 7:14 
QuestionRe: Anyone to help me? Pin
garfaoui29-Jul-07 22:39
garfaoui29-Jul-07 22:39 
QuestionTransparency Effect over Video Stream Pin
dkmr27-Jul-07 2:45
dkmr27-Jul-07 2:45 
AnswerRe: Transparency Effect over Video Stream Pin
Rage27-Jul-07 2:59
professionalRage27-Jul-07 2:59 
AnswerRe: Transparency Effect over Video Stream Pin
Mark Salsbery27-Jul-07 5:24
Mark Salsbery27-Jul-07 5:24 
GeneralRe: How to egalise two strings Pin
toxcct27-Jul-07 2:23
toxcct27-Jul-07 2:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.