Click here to Skip to main content
15,927,946 members
Home / Discussions / Article Writing
   

Article Writing

 
GeneralRe: Runtime resizing/moving of controls Pin
Todd Hoop11-Feb-02 7:08
Todd Hoop11-Feb-02 7:08 
GeneralEnumerating TCP ports and mapping them to PID (for XP) Pin
4-Feb-02 3:33
suss4-Feb-02 3:33 
Generalbarcode generator and reader source Pin
murd28-Jan-02 12:41
murd28-Jan-02 12:41 
GeneralRe: barcode generator and reader source Pin
moliate9-Feb-02 8:19
moliate9-Feb-02 8:19 
GeneralSpace Invaders. Pin
Arinte27-Jan-02 5:59
Arinte27-Jan-02 5:59 
GeneralRe: Space Invaders. Pin
PJ Arends27-Jan-02 6:15
professionalPJ Arends27-Jan-02 6:15 
Generalwinsock file transfer Pin
Kuniva17-Jan-02 10:35
Kuniva17-Jan-02 10:35 
GeneralRe: winsock file transfer Pin
Kashif Manzoor11-Feb-02 3:48
Kashif Manzoor11-Feb-02 3:48 
Kuniva,
Please see the attached sample code of a Winsock client. With a little bit of improvisation and MFC socket programming knowledge you could easily change it to your needs.
/***************************************/

/* This is the sample code for a client that send and receives some data from a server.*/

DownloadFileFromInternet(CString strAddress)
{

char buff[1024];
int s;
struct sockaddr_in a;
struct hostent *h;
WSADATA wsaData;
int SERVER_PORT = 1223;// The server port to which the client will connect.

// This call initializes the Winsock.dll
WSAStartup(0x101, &wsaData);

// Initializing the sockaddr_in datastructer with all zeroes.
memset(&a,0,sizeof(a));


// First assume an Internet dotted form address e.g. 198.168.0.1
a.sin_family = AF_INET;
a.sin_port = htons(SERVER_PORT); // Connect to the server port
a.sin_addr.s_addr = inet_addr("127.0.0.1"); // Connect to the localhost. Replace this address with the IP address of the server.

/////////////////////////////////////////////
// You may use descriptive Internet (e.g. www.microsoft.com) instead of the dotted (e.g. 127.0.0.1) one.
h = gethostbyname("www.microsoft.com"); // change this address to the desired server's address.
if (h != NULL)
{
a.sin_addr.s_addr = ((LPIN_ADDR)h->h_addr)->s_addr;
}
else
{
AfxMessageBox("Cannot resolve hostname\n");
WSACleanup();
return FALSE;
}


// create the socket.
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s == 0)
{
AfxMessageBox("Cannot establish connection: ");
WSACleanup(); // Winsock.dll cleanup code
return FALSE;
}

// socket succesfully created, now we may connect to the server
if (connect(s, (struct sockaddr *)&a, sizeof(a)))
{
//Can not establish the connection to the server
WSACleanup();
return FALSE;
}

// Connection established with the server. Start receiving data from the server
int k=0;
k = recv(s, buff, 1024, 0);
if (k<0)
{
// An error occurred while trying to receive data
closesocket(s); // close the opened socket.
WSACleanup(); // clean up Winsock.dll
return FALSE;
}
buff[k] = '\0';
// we will NULL terminate the received data from the server.


// We will send "WA-ALIKUMASALAM" to the server.
k=0;
while (k < int(strlen("WA-ALIKUMASALAM")))
{ // keep sending until all the data is sent.
k = send(s,"WA-ALIKUMASALAM",strlen("WA-ALIKUMASALAM"),0);
}

// We are finished. Now its time to close the socket
closesocket(s);
return TRUE;
}



/*****************************************/

Software Engineer (Techlogix (pvt)ltd)
Visiting Faculty Informatics, Lahore
GeneralImpressive Online "Game" Link needed Pin
Paul Watson14-Jan-02 1:07
sitebuilderPaul Watson14-Jan-02 1:07 
GeneralRe: Impressive Online "Game" Link needed Pin
Konstantin Vasserman14-Jan-02 4:13
Konstantin Vasserman14-Jan-02 4:13 
GeneralC# or C++ sample of the following VB example Pin
shypht9-Jan-02 18:27
shypht9-Jan-02 18:27 
GeneralDLL Dialog Pin
Matt Newman9-Jan-02 11:25
Matt Newman9-Jan-02 11:25 
GeneralRe: DLL Dialog Pin
jan larsen28-Feb-02 4:06
jan larsen28-Feb-02 4:06 
GeneralDrawing bitmaps Pin
Ray Kinsella8-Jan-02 6:10
Ray Kinsella8-Jan-02 6:10 
GeneralRe: Drawing bitmaps Pin
Paul Watson8-Jan-02 6:24
sitebuilderPaul Watson8-Jan-02 6:24 
GeneralRe: Drawing bitmaps Pin
Ray Kinsella8-Jan-02 6:31
Ray Kinsella8-Jan-02 6:31 
GeneralRe: Drawing bitmaps Pin
Paul Watson8-Jan-02 6:36
sitebuilderPaul Watson8-Jan-02 6:36 
GeneralRe: Drawing bitmaps Pin
Chris Maunder8-Jan-02 11:46
cofounderChris Maunder8-Jan-02 11:46 
GeneralRe: Drawing bitmaps Pin
Paul Watson9-Jan-02 5:01
sitebuilderPaul Watson9-Jan-02 5:01 
GeneralRe: Drawing bitmaps Pin
PJ Arends8-Jan-02 6:32
professionalPJ Arends8-Jan-02 6:32 
GeneralRe: Drawing bitmaps Pin
Paul Watson8-Jan-02 6:38
sitebuilderPaul Watson8-Jan-02 6:38 
GeneralRe: Drawing bitmaps Pin
Ravi Bhavnani8-Jan-02 6:33
professionalRavi Bhavnani8-Jan-02 6:33 
GeneralRe: Drawing bitmaps Pin
Ray Kinsella8-Jan-02 6:36
Ray Kinsella8-Jan-02 6:36 
GeneralTV Recorder Pin
haivh1-Jan-02 17:34
haivh1-Jan-02 17:34 
GeneralRe: TV Recorder Pin
Michael P Butler2-Jan-02 2:02
Michael P Butler2-Jan-02 2:02 

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.