|
I don't think that you can get the system clock directly, you need to use one of the time functions provided by the OS.
Manoj7390 wrote: How to clock in C++/C for the function of digital blocks. I'm not sure what you mean by this question.
Use the best guess
|
|
|
|
|
Do you mean simulate the flip flop? That is provide the clock (and other signals) by means of an array?
Veni, vidi, vici.
|
|
|
|
|
What i need is, i need to realize D-Flipflop(Digital block), which transfer the input to output when the clock is high.
Clock should be of 50% duty cycle, means equal amounts of ON and OF periods. How can i do this in C/C++.
|
|
|
|
|
Hi,
I am playing a video file and along with that a Progress bar starts, which indicates the progress of the video file. Now I want to know when the video file has finished playing so that I can reset the position of the Progress bar to 0.
Anybody have any idea regarding this. Any help will be appreciated.
It will be helpful if you can provide some sample code for the same.
Regards,
Mbatra
|
|
|
|
|
Did you notice the EventReceiver() method in the sample project I sent you? It's handling the EC_COMPLETE message.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Hi David,
Thanks for the info....I didn't notice that.
Now I have one doubt..I am able to figure out when the video play has finished. But at the completion of the video file, I am going to stop the time and reset the progress bar position to 0. Neither the timer is stopped nor the progress bar. Timer keeps on running and progress bar also keeps on stepping up.
Can u please help me how to stop the timer and progress bar.
Regards,
Mbatra
|
|
|
|
|
If you are using pretty much the same code as in the sample, it looks like you can simply add KillTimer(hOwner, MY_TIMEREVENT); to the DoStop() function.
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
Hi,
I am using DirectShow to Capture / Play / Stop a video. After capturing a video, when user clicks on the play video button, Video plays fine... But I want to display the progress bar along with the video which will show the user how much video portion is left to play. I also want to display the time along with progress bar, which will take the total duration of the video and will show the user how much time is left.
Anybody have any idea or suggestion for the above mentioned.
It will be very helpful if you can provide me the sample code for the same scenario.
Regards,
Mbatra
|
|
|
|
|
mbatra31 wrote: It will be very helpful if you can provide me the sample code for the same scenario. See here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Yes, our code is playing the video.
Regards,
Mbatra
|
|
|
|
|
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 :
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);
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;
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);
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);
}
}
|
|
|
|
|
Using your own IP address with that client is unlikely to work since you probably do not have a daytime listener on port 13. As to your server code, you need to explain where it fails and what errors you see.
Use the best guess
|
|
|
|
|
Hi. I'm getting bind error for the server's code.
|
|
|
|
|
Try using something other than one of the well known ports: 5001 for example.
Use the best guess
|
|
|
|
|
Seems like I cann't create a socket either with bind or Create with a parameter other than NULL
when do I get WSAEADDRNOTAVAIL
If I create a socket with Either Bind or Create with a NULL parameter for Create or Bind
ANd then I use GetSockame I get NULL for the IP address
IS this a strange occurence
|
|
|
|
|
ForNow wrote: IS this a strange occurence It's impossible to tell with this little amount of information. Show your code and the values of your variables and people will try to help you.
Use the best guess
|
|
|
|
|
a little background first I am writting a front end to the Hercules MainFrame Emulator this MFC C++ app
I also have a MVS started task communicating with this MFC C++ app when I first bought the Lap top
and moved in my code it worked the its a quad core lap top that I bought in August
Since then my machine has slowed and I am getting the timeouts
I Tried using Socket and Bind to Create the socket as opposed to just using the create
but in case it does take the IP address I use 192.168.1.4 which I think is the IP address of the laptop
I tried 192.168.1.111 as that is the ip address of my laptop 192.168.1.4 is routed to 192.168.1.111
I have a a loop in My CWinApp:: initinstance creating 4 socket threads
int i;
UINT start_port;
for (i = 0, start_port = 11007; i < 4; start_port++, i++)
{
#ifdef _DEBUG
msOld.Checkpoint();
#endif
threadptr[i] = new SockCLeintThread(start_port);
#ifdef _DEBUG
msnew.Checkpoint();
if( diffMemState.Difference(msOld, msnew))
{
diffMemState.DumpStatistics();
diffMemState.DumpAllObjectsSince();
}
#endif
if (threadptr[i] == NULL)
m_pMainWnd->MessageBox((LPCTSTR)"SockClientThreadFail",NULL,MB_ICONERROR);
threadptr[i]->CreateThread(CREATE_SUSPENDED,0,NULL);
threadptr[i]->flags.is_connected = 0;
threadptr[i]->ipaddr = (LPCTSTR)"192.168.1.4";
threadptr[i]->flags.busy = 0;
SetThreadName(threadptr[i]->m_nThreadID,thread[i]);
threadptr[i]->ResumeThread();
WaitForSingleObject(*pevent,INFINITE);
}
in My CWinTread initinstance I try to create the socket
BOOL SockCLeintThread::InitInstance()
{
int error_code, threadpri;
MSG m_msgCur;
extern void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName);
HANDLE mysocket;
int val = sizeof(int);
int *val_ptr = &val;
thisocket.Socket(SOCK_STREAM,FD_READ|FD_WRITE|FD_CONNECT,NULL,AF_INET);
if(thisocket.Bind(thisocket.port,NULL) == 0)
error_code = GetLastError();
int* len = new int;
thisocket.herccmd= new SOCKADDR;
if(thisocket.GetSockName(thisocket.herccmd,(int *)len) == 0)
error_code = GetLastError();
if(thisocket.GetSockOpt(SO_KEEPALIVE | SO_DEBUG, &thisocket.option,val_ptr, SOL_SOCKET) == 0)
error_code = GetLastError();
if(thisocket.SetSockOpt(SO_KEEPALIVE | SO_DEBUG, &thisocket.option,val, SOL_SOCKET) == 0)
error_code = GetLastError();
if(thisocket.AsyncSelectFD_READ|FD_WRITE|FD_CONNECT|FD_CLOSE|FD_OOB|FD_ACCEPT) == 0)
error_code = GetLastError();
if( thisocket.Connect(ipaddr,thisocket.port) == 0)
{
error_code = GetLastError();
}
else
flags.is_connected = 1;
return TRUE; }
the CASyncSockt::OnConnect
void SockClient :: OnConnect(int nErrorCode)
{
CAsyncSocket::OnConnect(nErrorCode);
CHERC_CMDApp* main_app;
main_app = (CHERC_CMDApp *) AfxGetApp();
main_app->pevent->SetEvent();
if (0 != nErrorCode)
{
switch( nErrorCode )
{
case WSAEADDRINUSE:
AfxMessageBox("The specified address is already in use.\n");
break;
case WSAEADDRNOTAVAIL:
AfxMessageBox("The specified address is not available from the local machine.\n");
break;
case WSAEAFNOSUPPORT:
AfxMessageBox("Addresses in the specified family cannot be used with this socket.\n");
break;
case WSAECONNREFUSED:
AfxMessageBox("The attempt to connect was forcefully rejected.\n");
break;
case WSAEDESTADDRREQ:
AfxMessageBox("A destination address is required.\n");
break;
case WSAEFAULT:
AfxMessageBox("The lpSockAddrLen argument is incorrect.\n");
break;
case WSAEINVAL:
AfxMessageBox("The socket is already bound to an address.\n");
break;
case WSAEISCONN:
AfxMessageBox("The socket is already connected.\n");
break;
case WSAEMFILE:
AfxMessageBox("No more file descriptors are available.\n");
break;
case WSAENETUNREACH:
AfxMessageBox("The network cannot be reached from this host at this time.\n");
break;
case WSAENOBUFS:
AfxMessageBox("No buffer space is available. The socket cannot be connected.\n");
break;
case WSAENOTCONN:
AfxMessageBox("The socket is not connected.\n");
break;
case WSAENOTSOCK:
AfxMessageBox("The descriptor is a file, not a socket.\n");
break;
case WSAETIMEDOUT:
AfxMessageBox("The attempt to connect timed out without establishing a connection. \n");
break;
default:
TCHAR szError[256];
wsprintf(szError, "OnConnect error: %d", nErrorCode);
AfxMessageBox(szError);
break;
}
AfxMessageBox("Please close the application");
}
SockCLeintThread* threadptr;
threadptr = (SockCLeintThread *) AfxGetThread();
threadptr->flags.is_connected = 1;
AsyncSelect(FD_WRITE);
}
The CwinThread Derived Class
class SockCLeintThread : public CWinThread {
public:
DECLARE_DYNCREATE(SockCLeintThread)
public:
SockCLeintThread();
SockCLeintThread(UINT myport);
~SockCLeintThread();
CWnd *sendwindow;
CWnd *call_wnd;
char *thread_id;
SockClient thisocket; <== void Sendit(WPARAM, LPARAM);
void Receiveit(WPARAM, LPARAM);
LPCTSTR ipaddr;
BOOL idle;
struct {
unsigned int is_connected : 1;
unsigned int busy : 1;
unsigned int not_connected : 1;
} flags;
protected:
virtual BOOL InitInstance(); DECLARE_MESSAGE_MAP()
};
The CAsyncSocket Derived Class
class SockClient : public CAsyncSocket
{
DECLARE_SERIAL(SockClient)
public:
SockClient();
SockClient(UINT myport);
~SockClient();
char *sockbuffer; int num_buff;
int thread_no;
UINT port;
SOCKADDR* herccmd; SOCKADDR MVS; int option;
private:
int busy; protected:
virtual void OnReceive(int nErrorCode);
virtual void OnSend(int nErrorCode);
virtual void OnConnect(int nErrorCode);
virtual void OnClose(int nErrorCode);
};
I know its not formatted that neatly but I am always fixing the code
Thanks
|
|
|
|
|
ForNow wrote: I know its not formatted that neatly Understatement of the year!
Use the best guess
|
|
|
|
|
|
OK, but please don't just dump a load of code like the above, and expect people to figure out what's happening. Add some proper detail about exactly where it is going wrong and what the values of the relevant variables are at the time of the error.
Use the best guess
|
|
|
|
|
HI
Hope this is better
As I said I bought my quad core laptop in August and my code was running faster
as of now my connections time out
One of my questions is how come when I do a GetSockName after a Successful Bind
code is in The Dervied CWinThread SockCleintThread::Initinstance
The ip address in he SOCKADDR structure is 0 ?
The underlying technology was written By David "FISH" Trout
http://www.softdevlabs.com/Hercules/ctci-w32-readme.html[^]
class SockClient : public CAsyncSocket
{
DECLARE_SERIAL(SockClient)
public:
SockClient();
SockClient(UINT myport);
~SockClient();
char *sockbuffer; int num_buff;
int thread_no;
UINT port;
SOCKADDR* herccmd; SOCKADDR* MVS; int option;
private:
int busy;
protected:
virtual void OnReceive(int nErrorCode);
virtual void OnSend(int nErrorCode);
virtual void OnConnect(int nErrorCode);
virtual void OnClose(int nErrorCode);
class SockCLeintThread : public CWinThread {
public:
DECLARE_DYNCREATE(SockCLeintThread)
public:
SockCLeintThread();
SockCLeintThread(UINT myport);
~SockCLeintThread();
CWnd *sendwindow;
CWnd *call_wnd;
char *thread_id;
SockClient thisocket; void Sendit(WPARAM, LPARAM);
void Receiveit(WPARAM, LPARAM);
LPCTSTR ipaddr;
BOOL idle;
struct {
unsigned int is_connected : 1;
unsigned int busy : 1;
unsigned int not_connected : 1;
} flags;
protected:
virtual BOOL InitInstance(); DECLARE_MESSAGE_MAP()
};
for (i = 0, start_port = 11007; i < 4; start_port++, i++)
{
#ifdef _DEBUG
msOld.Checkpoint();
#endif
threadptr[i] = new SockCLeintThread(start_port);
#ifdef _DEBUG
msnew.Checkpoint();
if( diffMemState.Difference(msOld, msnew))
{
diffMemState.DumpStatistics();
diffMemState.DumpAllObjectsSince();
}
#endif
if (threadptr[i] == NULL)
m_pMainWnd->MessageBox((LPCTSTR)"SockClientThreadFail",NULL,MB_ICONERROR);
threadptr[i]->CreateThread(CREATE_SUSPENDED,0,NULL);
threadptr[i]->flags.is_connected = 0;
threadptr[i]->ipaddr = (LPCTSTR)"192.168.1.4";
threadptr[i]->flags.busy = 0;
SetThreadName(threadptr[i]->m_nThreadID,thread[i]);
threadptr[i]->ResumeThread();
WaitForSingleObject(*pevent,INFINITE);
}
BOOL SockCLeintThread::InitInstance()
{
int error_code, threadpri;
MSG m_msgCur;
extern void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName);
HANDLE mysocket;
int val = sizeof(int);
int *val_ptr = &val;
thisocket.Socket(SOCK_STREAM,FD_READ|FD_WRITE|FD_CONNECT,NULL,AF_INET);
if(thisocket.Bind(thisocket.port,NULL) == 0)
error_code = GetLastError();
int* len = new int;
thisocket.herccmd= new SOCKADDR;
if(thisocket.GetSockName(thisocket.herccmd,(int *)len) == 0)
error_code = GetLastError();
if(thisocket.GetSockOpt(SO_KEEPALIVE | SO_DEBUG, &thisocket.option,val_ptr, SOL_SOCKET) == 0)
error_code = GetLastError();
if(thisocket.SetSockOpt(SO_KEEPALIVE | SO_DEBUG, &thisocket.option,val, SOL_SOCKET) == 0)
error_code = GetLastError();
if( thisocket.Connect(ipaddr,thisocket.port) == 0)
{
error_code = GetLastError();
}
else
flags.is_connected = 1;
return TRUE;
}
void SockClient :: OnConnect(int nErrorCode)
{
CAsyncSocket::OnConnect(nErrorCode);
CHERC_CMDApp* main_app;
main_app = (CHERC_CMDApp *) AfxGetApp();
main_app->pevent->SetEvent();
if (0 != nErrorCode)
{
switch( nErrorCode )
{
case WSAEADDRINUSE:
AfxMessageBox("The specified address is already in use.\n");
break;
case WSAEADDRNOTAVAIL:
AfxMessageBox("The specified address is not available from the local machine.\n");
break;
case WSAEAFNOSUPPORT:
AfxMessageBox("Addresses in the specified family cannot be used with this socket.\n");
break;
case WSAECONNREFUSED:
AfxMessageBox("The attempt to connect was forcefully rejected.\n");
break;
case WSAEDESTADDRREQ:
AfxMessageBox("A destination address is required.\n");
break;
case WSAEFAULT:
AfxMessageBox("The lpSockAddrLen argument is incorrect.\n");
break;
case WSAEINVAL:
AfxMessageBox("The socket is already bound to an address.\n");
break;
case WSAEISCONN:
AfxMessageBox("The socket is already connected.\n");
break;
case WSAEMFILE:
AfxMessageBox("No more file descriptors are available.\n");
break;
case WSAENETUNREACH:
AfxMessageBox("The network cannot be reached from this host at this time.\n");
break;
case WSAENOBUFS:
AfxMessageBox("No buffer space is available. The socket cannot be connected.\n");
break;
case WSAENOTCONN:
AfxMessageBox("The socket is not connected.\n");
break;
case WSAENOTSOCK:
AfxMessageBox("The descriptor is a file, not a socket.\n");
break;
case WSAETIMEDOUT:
AfxMessageBox("The attempt to connect timed out without establishing a connection. \n");
break;
default:
TCHAR szError[256];
wsprintf(szError, "OnConnect error: %d", nErrorCode);
AfxMessageBox(szError);
break;
}
AfxMessageBox("Please close the application");
}
***********************************************************************
* From MVS started Task
* A Select does all socket I/O including listens
* From MFC C++ herccmd
*
SELECT_IT DS 0H
EZASMI TYPE=SELECT, Issue Macro X
MAXSOC=MAXSOC1, SPECIFY MAXIMUM NUMBER OF SOCKETS X
TIMEOUT=TIMEVAL, X
RSNDMSK=RSNDMSK, READ MASK X
RRETMSK=RRETMSK, RETURN FROM READ X
WSNDMSK=WSNDMSK, WRITE MASK X
WRETMSK=WRETMSK, RETURN FROM WRITE X
ESNDMSK=ESNDMSK, X
ERETMSK=ERETMSK, X
ERRNO=ERRNO, (Specify ERRNO field) X
RETCODE=RETCODE, (Specify RETCODE field) X
ECB=MY_ECB, MAIN TASK ECB X
ERROR=ERROR, Abend if Macro error X
TASK=MYTIE, X
MF=(E,MY_PARM)
|
|
|
|
|
ForNow wrote: The underlying technology was written By David "FISH" Trout Then I guess you know who to contact about this.
Use the best guess
|
|
|
|
|
Don't think it's strange that after I do a bind
Of a socket I cann't get its ip address
|
|
|
|
|
ForNow wrote: Don't think it's strange that after I do a bind Of a socket I cann't get its ip address Not if you read the documentation[^].
Use the best guess
|
|
|
|
|
Hi, I am working with network simulator - 3, where the programming language is C++, I have created two nodes and sending data from server to client, its showing number of packets sent, but its not receiving, showing 0! bytes in client side.
Please help me if any one knows NS-3.
Thanking you...
|
|
|
|
|