Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - user

Pages: [1]
1
Network / PLEASE REPLY.Its urgent.
« on: March 24, 2011, 10:59:37 am »
PLEASE REPLY.Its urgent.

2
Network / well,here's the code...PLEASE HELP
« on: March 23, 2011, 03:30:22 pm »
Code: [Select]
#include <windows.h>
#include "stdafx.h"
#include "nettrial2.h"
#include "resource.h"
#include "commdlg.h"

#include "SFML/System.hpp"
#include "SFML/Network/IPAddress.hpp"
#include "SFML/Network/Http.hpp"
#include "SFML/Network/SocketUDP.hpp"
#include "SFML/Network/SocketHelper.hpp"
#include "string.h"
#include "iostream"

LRESULT WINAPI MainWndProc( HWND, UINT, WPARAM, LPARAM );
BOOL CALLBACK AboutProc( HWND, UINT, WPARAM, LPARAM );
BOOL CALLBACK IpProc( HWND, UINT, WPARAM, LPARAM );
int CALLBACK sendConnRequest(char*);
int CALLBACK getConnRequest(sf::SocketUDP);

int flag=1;
unsigned short P1sendPort=3000,P1receivePort=3001,P2receivePort=4000,P2semdPort=4001;
sf::IPAddress P2addr;

int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine,int iCmdShow )
{
   WNDCLASS wc;
   MSG msg;
   HWND hWnd;
   HMENU hmenu;
   if( !hPrevInstance )
   { wc.lpszClassName = TEXT("LetterLink");
wc.lpfnWndProc = MainWndProc;
wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
wc.lpszMenuName = (LPCWSTR)IDC_LETTERLINK;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
RegisterClass( &wc ); }
   hWnd = CreateWindow( TEXT("LetterLink"),TEXT("LetterLink"),WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,    0,    0,
   CW_USEDEFAULT,    CW_USEDEFAULT,    NULL,    NULL,    hInstance,   NULL
);
   hmenu=LoadMenu(hInstance,MAKEINTRESOURCE(IDC_LETTERLINK));
ShowWindow( hWnd, iCmdShow );
UpdateWindow(hWnd);
while( GetMessage( &msg, NULL, 0, 0 ) ) {
    TranslateMessage( &msg );
    DispatchMessage( &msg );
}
return 0;
}
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam,    LPARAM lParam )
{
PAINTSTRUCT ps;
HDC hDC;
static HINSTANCE hinst;
static HMENU hmenu;
static int cxClient, cyClient,cxChar,cyChar;
TEXTMETRIC tm;
int sel;

switch( msg ) {
case WM_CREATE:
hinst=((LPCREATESTRUCT)lParam)->hInstance;
hmenu=GetMenu(hWnd);
hDC = GetDC (hWnd) ;
     GetTextMetrics (hDC, &tm) ;
     cxChar = tm.tmAveCharWidth ;
     cyChar = tm.tmHeight + tm.tmExternalLeading ;
     ReleaseDC (hWnd, hDC) ;
break;
case WM_SIZE:
    cxClient = LOWORD(lParam);
    cyClient = HIWORD(lParam);
    break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_NEW:
sel=MessageBox(hWnd,TEXT("Are you player 1?"),TEXT(""),MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL);
if(sel==IDYES)
{
//set flags
DialogBox(hinst,(LPCWSTR)IDD_IPBOX,hWnd,(DLGPROC)IpProc);
}
else
{
int cn=getData();
if(cn==1)
MessageBox(hWnd,TEXT("Connection Successful!"),TEXT("Connected"),MB_OK);
}
EnableMenuItem(hmenu,ID_NEW,MF_GRAYED);
break;
case ID_ABOUT:
DialogBox(hinst,(LPCWSTR)IDD_ABOUTBOX,hWnd,(DLGPROC)AboutProc);
break;
case ID_EXIT:
PostQuitMessage(0);
break;
}
return 0;
case WM_PAINT:
    hDC = BeginPaint( hWnd, &ps );

EndPaint( hWnd, &ps );
    return 0;
case WM_DESTROY:
    PostQuitMessage( 0 );
    return 0;
default:
     return( DefWindowProc( hWnd, msg, wParam, lParam ));
}
  return 0;
}

BOOL CALLBACK AboutProc( HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
LPWSTR str=TEXT("");
switch (msg)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
hdc=GetDC(hdlg);
// GetWindowText(GetDlgItem(hdlg,IDx),str,5);
TextOut(hdc,100,100,(LPCWSTR)str,5);
EndDialog(hdlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}

BOOL CALLBACK IpProc( HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
static HWND one,two,three,four;
int valid=1,len1,len2,len3,len4;
static TCHAR addr[3];
char *address="";

int connected;
switch (msg)
{
case WM_INITDIALOG:
return TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDCONNECT)
{
//not pasting the other non-necessary code...

                              if(valid==1)
{


connected=sendConnRequest("192.168.3.11");
if(connected==1)
MessageBox(hdlg,TEXT("Connection Successful!"),TEXT("Connected"),MB_OK);
else
MessageBox(hdlg,TEXT("Incorrect IP address!"),TEXT("Error"),MB_OK);
}
}
break;
case WM_CLOSE:
EndDialog(hdlg, LOWORD(wParam));
return TRUE;
}
return FALSE;
}



int CALLBACK sendConnRequest(char *addr)
{
    static sf::SocketUDP P1,P2;
int conn=0;
//connect,get back a flag which is an indication of the server sending back data,return the flag
if(!P1.Bind(P1sendPort))
{
return 0;
}
if(!P2.Bind(P2receivePort))
{
return 0;
}
P2.SetBlocking(false);
P2addr=sf::IPAddress(addr);
TCHAR Message[3]=TEXT("hi");
if(!P2addr.IsValid())
return 0;
if(P1.Send((char*)Message,sizeof((char*)Message),P2addr,P2receivePort)==sf::Socket::Done)
conn=getConnRequest(P2);
if(conn==1)
return 1;
else
return 0;
}



int CALLBACK getConnRequest(sf::SocketUDP P2)
{
if(!P2.Bind(P2receivePort))
{
return 0;
}
std::size_t Received;
sf::IPAddress ClientAddress;
unsigned short ClientPort;
TCHAR Message[3]=TEXT("");
TCHAR temp[3]=TEXT("hi");

sf::Socket::Status st=P2.Receive((char*)Message, sizeof(Message), Received, ClientAddress, ClientPort);
if(st==sf::Socket::Done)
{
if(strcmp((char*)Message,(char*)temp)==0)
return 1;
}
return 0;
}


how to actually run the program? I mean, it won't run if use the same code in both machines, because then,my machine will call its own getConnRequest(). I want the other machine's getConnRequest() to be called.And i want the other machine to send back an ack. when it recieves my machine's message.Then i want both the machines to send and receive data.

3
Network / Sample code for networking
« on: March 22, 2011, 01:19:25 pm »
Hi,
i wrote a code,in which one machine(A) sends "hi" to another machine(B).Now A sends the data successfully.But B does not receive it.I've bound the socket to the port but still,the status shows NotReady(at B).What is to be done?
Also, i need B to send back an ack to A.can u please help me out by showin a code on this.I need it for my project asap.

PS : I've seen the sample codes that are the tutorial,but donno y my code is not working.

4
Network / UDP packet not received by server
« on: February 22, 2011, 09:33:16 am »
Thanku Thanku Thanks a lot!!!!!!!  :)

5
Network / how to do that?
« on: February 21, 2011, 12:21:05 pm »
u mean i cant run both on the same machine?if not, then can u please tell me how to connect two machines and make the code run?

6
Network / UDP packet not received by server
« on: February 20, 2011, 06:36:43 am »
Code: [Select]
unsigned short Port=4567;
DoClientUDP(hWnd,Port);

void DoClientUDP(HWND hwnd,unsigned short Port)
{
  sf::IPAddress ServerAddress;
  ServerAddress=sf::IPAddress::LocalHost;

  while (!ServerAddress.IsValid());
 
  sf::SocketUDP Client;
  unsigned short CPort=4323;

  Client.Bind(CPort);

   char Message[3] = "Hi";

    if (Client.Send(Message, sizeof(Message),ServerAddress, Port) != sf::Socket::Done)
          return;
   else
   {
     DoServerUDP(hwnd);
     Client.Close();
   }
}

void DoServerUDP(HWND hwnd)
{
  unsigned short Port=4567;
  sf::SocketUDP Server;

 char Buffer[200]="";
 std::size_t Received;

 sf::IPAddress ClientAddress=sf::IPAddress::LocalHost;
 
 unsigned short ClientPort;
 char Message[3]="";

 if (!Server.Bind(Port))
        return;
 Server.SetBlocking(false);

 sf::Socket::Status SocketStatus=sf::Socket::Done;
 SocketStatus=(Server.Receive(Message, sizeof(Message), Received, ClientAddress, ClientPort));

Server.Close();

}



This is my code. Now when i execute the statement(Server.Receive), the SocketStatus becomes NotReady.The client sends the message but the server does not receive it.What should be done???Please HELP!!!

Pages: [1]