Click here to Skip to main content
15,921,467 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: how to install windows NT services Pin
prasad_som14-Sep-05 22:29
prasad_som14-Sep-05 22:29 
AnswerRe: how to install windows NT services Pin
ThatsAlok14-Sep-05 22:44
ThatsAlok14-Sep-05 22:44 
GeneralRe: how to install windows NT services Pin
ThatsAlok6-Sep-05 0:59
ThatsAlok6-Sep-05 0:59 
AnswerRe: how to install windows NT services Pin
Marc Soleda5-Sep-05 20:44
Marc Soleda5-Sep-05 20:44 
QuestionMDI MFC App Question Pin
LighthouseJ5-Sep-05 17:22
LighthouseJ5-Sep-05 17:22 
AnswerRe: MDI MFC App Question Pin
MailtoGops5-Sep-05 22:07
MailtoGops5-Sep-05 22:07 
QuestionAbout Dialog bar size Pin
zhaopi5-Sep-05 17:17
zhaopi5-Sep-05 17:17 
Questionserver and client Pin
Member 21610045-Sep-05 16:00
Member 21610045-Sep-05 16:00 
I have a server and client source code and I not very understand the send and receive part of the program. After I execute the program, it show Bytes send: 21. I don't know why it is 21. Can somebody tell me?

Below is the code for the server:

#include "stdafx.h"
#include "winsock2.h"

void main()
{

// Initialize Winsock.
WSADATA wsaData;
int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );
if ( iResult != NO_ERROR )
{
printf("Error at WSAStartup()\n");
}

// Create a socket.
SOCKET m_socket;
m_socket = socket( AF_INET, SOCK_STREAM, 0 );

if ( m_socket == INVALID_SOCKET )
{
printf( "Error at socket(): %ld\n", WSAGetLastError());
WSACleanup();
return;
}

// Bind the socket.
sockaddr_in service;

service.sin_family = AF_INET;
service.sin_addr.s_addr = inet_addr( "127.0.0.1" );
service.sin_port = htons( 60000 );

if ( bind( m_socket, (SOCKADDR*) &service, sizeof(service) ) == SOCKET_ERROR )
{
printf( "bind() failed.\n" );
closesocket(m_socket);
return;
}

// Listen on the socket.
if ( listen( m_socket, 1 ) == SOCKET_ERROR )
{
printf( "Error listening on socket.\n");
}

// Accept connections.
SOCKET AcceptSocket;

printf( "Waiting for a client to connect...\n" );
while (1)
{
AcceptSocket = SOCKET_ERROR;
while ( AcceptSocket == SOCKET_ERROR )
{
AcceptSocket = accept( m_socket, NULL, NULL );
}
printf( "Client Connected.\n");
m_socket = AcceptSocket;
break;
}

// Send and receive data.
int bytesSent;
int bytesRecv = SOCKET_ERROR;
char sendbuf[32] = "Server: Sending Data.";
char recvbuf[32] = "";

bytesRecv = recv( m_socket, recvbuf, 32, 0 );
printf( "Bytes Recv: %ld\n", bytesRecv );

bytesSent = send( m_socket, sendbuf, strlen(sendbuf), 0 );
printf( "Bytes Sent: %ld\n", bytesSent );

return;
}
AnswerRe: server and client Pin
Christian Graus5-Sep-05 16:04
protectorChristian Graus5-Sep-05 16:04 
GeneralRe: server and client Pin
Moak6-Sep-05 1:18
Moak6-Sep-05 1:18 
AnswerRe: server and client Pin
snprani5-Sep-05 22:31
snprani5-Sep-05 22:31 
AnswerRe: server and client Pin
snprani5-Sep-05 22:33
snprani5-Sep-05 22:33 
Questionproperties Pin
zildjohn015-Sep-05 13:37
zildjohn015-Sep-05 13:37 
AnswerRe: properties Pin
Christian Graus5-Sep-05 13:44
protectorChristian Graus5-Sep-05 13:44 
Questionicon Pin
Anonymous5-Sep-05 11:14
Anonymous5-Sep-05 11:14 
AnswerRe: icon Pin
oustar5-Sep-05 15:19
oustar5-Sep-05 15:19 
General[Message Deleted] Pin
Ali Tavakol5-Sep-05 19:57
Ali Tavakol5-Sep-05 19:57 
AnswerRe: icon Pin
toxcct5-Sep-05 21:17
toxcct5-Sep-05 21:17 
QuestionDirectX OverLay ? Pin
seq-5-Sep-05 11:08
seq-5-Sep-05 11:08 
QuestionAddstore() [Outlook Automation] problem Pin
_kane_5-Sep-05 10:25
_kane_5-Sep-05 10:25 
QuestionDEBUG_NEW Pin
Klempie5-Sep-05 8:27
Klempie5-Sep-05 8:27 
AnswerRe: DEBUG_NEW Pin
Bob Stanneveld5-Sep-05 9:41
Bob Stanneveld5-Sep-05 9:41 
Questionhow to get the size of an array Pin
Waleed Eissa5-Sep-05 8:00
Waleed Eissa5-Sep-05 8:00 
AnswerRe: how to get the size of an array Pin
Chris Losinger5-Sep-05 8:07
professionalChris Losinger5-Sep-05 8:07 
GeneralRe: how to get the size of an array Pin
Bob Stanneveld5-Sep-05 9:44
Bob Stanneveld5-Sep-05 9:44 

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.