Click here to Skip to main content
15,892,059 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to know when a video file has finished playing....MFC? Pin
mbatra3131-May-13 4:21
mbatra3131-May-13 4:21 
QuestionRe: How to know when a video file has finished playing....MFC? Pin
David Crow31-May-13 4:28
David Crow31-May-13 4:28 
AnswerRe: How to know when a video file has finished playing....MFC? Pin
mbatra3131-May-13 22:11
mbatra3131-May-13 22:11 
AnswerRe: How to know when a video file has finished playing....MFC? Pin
SoMad31-May-13 22:44
professionalSoMad31-May-13 22:44 
QuestionHow to display a progress bar while video is playing...MFC.? Pin
mbatra3130-May-13 19:51
mbatra3130-May-13 19:51 
AnswerRe: How to display a progress bar while video is playing...MFC.? Pin
David Crow31-May-13 4:02
David Crow31-May-13 4:02 
GeneralRe: How to display a progress bar while video is playing...MFC.? Pin
mbatra3131-May-13 4:04
mbatra3131-May-13 4:04 
Questionbinding client and server Pin
noislude30-May-13 10:13
noislude30-May-13 10:13 
Hi all. I know almost nothing about client-server programming and I wish you could tell me how to make these two programs work together. I tried running both in terminal with my IP address without success. Thanks Smile | :) :

client

#include <sys/socket.h>
#include <stdio.h>
#include <strings.h> 
#include <arpa/inet.h> 
#include <unistd.h> 
#include <stdlib.h>

#define MAXLINE 100
#define SA struct sockaddr

int main(int argc, char **argv)
{
	int    sockfd, n;
	char   recvline[MAXLINE + 1];
	struct sockaddr_in	servaddr;

	if (argc != 2)
      fprintf(stderr, "usage: a.out <IPaddress>");

	if ( (sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0)
		fprintf(stderr, "socket error\n");

	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port   = htons(13);	/* daytime server */
	if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0)
		fprintf(stderr, "inet_pton error for %s", argv[1]);

	if (connect(sockfd, (SA *) &servaddr, sizeof(servaddr)) < 0)
		fprintf(stderr, "connect error\n");

	while ( (n = read(sockfd, recvline, MAXLINE)) > 0) {
		recvline[n] = 0;	/* null terminate */
		if (fputs(recvline, stdout) == EOF)
	       fprintf(stderr, "fputs error\n");
	}
	if (n < 0)
	  fprintf(stderr, "read error\n");

	exit(0);
}


server

#include <sys/socket.h>
#include <stdio.h>
#include <strings.h> 
#include <arpa/inet.h> 
#include <unistd.h> 
#include <stdlib.h>
#include <time.h> 
#include <errno.h> 
#include <string.h> 

#define	LISTENQ 1024
#define MAXLINE 4096
#define SA struct sockaddr

void Close(int fd) 
{ 
  if(close(fd) == -1) 
    fprintf(stderr, "Can't close connection\n");	
} 	

void Write(int fd, void *ptr, size_t nbytes)
{
	if (write(fd, ptr, nbytes) != nbytes)
		fprintf(stderr, "Write error\n");
}

int Accept(int fd, struct sockaddr *sa, socklen_t *salenptr)
{
	int	n;
again:
	if ((n = accept(fd, sa, salenptr)) < 0) {
    #ifdef EPROTO
	  if (errno == EPROTO || errno == ECONNABORTED)
	#else
	  if (errno == ECONNABORTED)
	#endif
	  goto again;
	  else
	    fprintf(stderr, "accept error\n");
	}
	return(n);
}

int main(int argc, char **argv)
{
	int					listenfd, connfd;
	struct sockaddr_in	servaddr;
	char				buff[MAXLINE];
	time_t				ticks;

	if((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) 
	  fprintf(stderr, "Socket error\n"); 

	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family      = AF_INET;
	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	servaddr.sin_port        = htons(13);	/* daytime server */

	if(bind(listenfd, (SA *) &servaddr, sizeof(servaddr)) < 0) 
	  fprintf(stderr, "Bind error\n");

	if(listen(listenfd, LISTENQ) < 0) 
	  fprintf(stderr, "Can't listen\n");

	for ( ; ; ) {
		connfd = Accept(listenfd, (SA *) NULL, NULL);

        ticks = time(NULL);
        snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks));
        Write(connfd, buff, strlen(buff));

		Close(connfd);
	}
}

AnswerRe: binding client and server Pin
Richard MacCutchan30-May-13 21:11
mveRichard MacCutchan30-May-13 21:11 
GeneralRe: binding client and server Pin
noislude31-May-13 2:00
noislude31-May-13 2:00 
GeneralRe: binding client and server Pin
Richard MacCutchan31-May-13 6:50
mveRichard MacCutchan31-May-13 6:50 
Questionipaddress for CAsyncSocket Class Pin
ForNow30-May-13 2:27
ForNow30-May-13 2:27 
AnswerRe: ipaddress for CAsyncSocket Class Pin
Richard MacCutchan30-May-13 2:54
mveRichard MacCutchan30-May-13 2:54 
GeneralRe: ipaddress for CAsyncSocket Class Pin
ForNow30-May-13 4:48
ForNow30-May-13 4:48 
GeneralRe: ipaddress for CAsyncSocket Class Pin
Richard MacCutchan30-May-13 5:27
mveRichard MacCutchan30-May-13 5:27 
GeneralRe: ipaddress for CAsyncSocket Class Pin
ForNow30-May-13 5:54
ForNow30-May-13 5:54 
GeneralRe: ipaddress for CAsyncSocket Class Pin
Richard MacCutchan30-May-13 6:21
mveRichard MacCutchan30-May-13 6:21 
GeneralRe: ipaddress for CAsyncSocket Class Pin
ForNow31-May-13 4:34
ForNow31-May-13 4:34 
GeneralRe: ipaddress for CAsyncSocket Class Pin
Richard MacCutchan31-May-13 6:52
mveRichard MacCutchan31-May-13 6:52 
GeneralRe: ipaddress for CAsyncSocket Class Pin
ForNow31-May-13 9:29
ForNow31-May-13 9:29 
GeneralRe: ipaddress for CAsyncSocket Class Pin
Richard MacCutchan31-May-13 10:36
mveRichard MacCutchan31-May-13 10:36 
QuestionNetwork simulator -3 : problem in recieving data. Pin
Manoj739029-May-13 19:29
Manoj739029-May-13 19:29 
AnswerRe: Network simulator -3 : problem in recieving data. Pin
dusty_dex30-May-13 3:35
dusty_dex30-May-13 3:35 
QuestionC++ program is not building in G++ (Ubuntu) Pin
Manoj739029-May-13 19:24
Manoj739029-May-13 19:24 
AnswerRe: C++ program is not building in G++ (Ubuntu) Pin
Richard MacCutchan29-May-13 20:58
mveRichard MacCutchan29-May-13 20:58 

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.