Niestety nie dziala wiec zostaja fragmenty najpierv czesci SERVERA
//...
// petla komunikatow bo pewnie tu jest blad
//
LRESULT CALLBACK MainWndProc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
switch(message)
{
case WM_USER:
switch(WSAGETSELECTEVENT(lParam))
{
case FD_WRITE:
send(m_socket, buf, 1024, 0);
break;
case FD_ACCEPT:
MessageBox(NULL, "UDALO SIE", "INF", NULL);
break;
case FD_READ:
break;
}
break;
case WM_CREATE:
//...
break;
case WM_COMMAND:
hwnd = (HWND)lParam;
if((hwnd == hwndWys) && (HIWORD(wParam) == BN_CLICKED))
{
send(m_socket, buf, 1024, 0);
}
// tworzenie socketa i nawiazywanie polaczenia
if((hwnd == hwndButton) && (HIWORD(wParam) == BN_CLICKED))
{
int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );
if ( iResult != NO_ERROR )
{
MessageBox(NULL, "ERROR", "ERROR", NULL);
}
m_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if ( m_socket == INVALID_SOCKET )
{
MessageBox(NULL, "ERROR", "ERROR", NULL);
WSACleanup();
}
sockaddr_in service;
service.sin_family = AF_INET;
service.sin_addr.s_addr = inet_addr( "127.0.0.1" );
service.sin_port = htons( 27015 );
if ( bind( m_socket, (SOCKADDR*) &service, sizeof(service) ) == SOCKET_ERROR )
{
MessageBox(NULL, "ERROR", "ERROR", NULL);
closesocket(m_socket);
}
if ( listen( m_socket, 1 ) == SOCKET_ERROR )
MessageBox(NULL, "ERROR", "ERROR", NULL);
MessageBox(NULL, "CZEKANIE NA POLACZENIE", "ERROR", NULL);
while (1)
{
AcceptSocket = SOCKET_ERROR;
while ( AcceptSocket == SOCKET_ERROR ) {
AcceptSocket = accept( m_socket, NULL, NULL );
}
MessageBox(NULL, "POLACZONO", "ERROR", NULL);
m_socket = AcceptSocket;
break;
}
}
WSAAsyncSelect(m_socket, hwnd, WM_USER, FD_ACCEPT | FD_READ | FD_WRITE);
break;
i to chyba tyle waznego teraz kod klienta
LRESULT CALLBACK MainWndProc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
switch(message)
{
case WM_CREATE:
//...
break;
case WM_COMMAND:
hwnd = (HWND)lParam;
if((hwnd == hwndButton) && (HIWORD(wParam) == BN_CLICKED))
{
int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );
if ( iResult != NO_ERROR )
{
MessageBox(NULL, "Błąd przy starcie WSA", "ERROR", NULL);
}
m_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if ( m_socket == INVALID_SOCKET )
{
MessageBox(NULL, "Błąd w gnieździe", "ERROR", NULL);
WSACleanup();
}
sockaddr_in clientService;
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr( "127.0.0.1" );
clientService.sin_port = htons( 27015 );
if ( connect( m_socket, (SOCKADDR*) &clientService, sizeof(clientService) ) == SOCKET_ERROR)
{
MessageBox(NULL, "Nie udało się połączyć", "ERROR", NULL);
WSACleanup();
}
WSAAsyncSelect(m_socket, hwnd, WM_USER, FD_CONNECT | FD_READ | FD_WRITE);
}
break;
case WM_USER:
switch(WSAGETSELECTEVENT(lParam))
{
case FD_READ:
recv(m_socket, buf, 1024, 0);
NewLine(buf, hwndRich) ; // wypisanie kazdej nowej wiadomosci w nowym wierszu
break;
case FD_CONNECT:
break;
case FD_WRITE:
break;
}
break;
i to chyba wszystko mam nadzieje ze pomozesz bo sie juz z tym mecze od kilku dni i na kazdym forum jest jak to zrobic ale u mnie to nie dziala :D mam nadzieje ze o niczym nie zapomnialem