C++ :: Program Output That Doesn't Wait For Replies But Still Captures Them
Jul 21, 2013
I am trying to write a program that can communicate over a very latent internet connection involving a cellular modem. I have some software packages that handle all the telnet like business and will pipe stdout and stdin to a program I can have it execute.
The problem I am running into is that I have to send about 900 ASCII commands to an instrument to request data but it takes about a second between when a command goes out and when a reply comes back. This will wind up taking a very long time and I am looking to speed it up. All of the commands are independent of the reply so what I need to do is create a program that can send all 900 commands with maybe 10ms break between them and to not wait for a reply. It then needs to read the replies and write them straight to a file.
It seems like this should be achievable in C++ but I only have a very basic understanding of the language and thus am not sure where to start.
I am open to using other languages but thought C++ would be a reasonably good start so I can distribute the program to my coworkers. All of our work machines are Windows but if there is a simpler solution from Linux, I should be able to work something out. I'm just trying to avoid complication.
I'm working on a project that requires to make modifications to certain functions. So, I'll copy and paste the function to a new source code so I'm just working on the function with the entire program running. When I run the function by itself, it works fine. But when I copy and paste the function back to it's spot, the program doesn't wait for input at the cin.getline & it did wait when I ran just the function by itself. I'm using Dev C++ if that makes a difference.
The program will ask for the user to enter a value for x, then compute the following polynomial: 3x^5 + 2x^4 - 5x^3 - x^2 + 7x - 6.However, when I double check it with my calculator I get a wrong answer for random values of x. To simplify my problem I'm using only integers.
Code:
#include <stdio.h> int main(void) { int x, polynomial; }
I am making a program which is going to print out a head image according to the input values entered by the user. Here is the code:
Code: #include <iostream> #include <string> using namespace std; void Sides() // draws the sides to take proportion
[Code] .....
At first i tried to work program like:
Code: cout << "plase enter which way you want to print out the head, with parted hair or bald." << endl; cin >> headstyle; if (headstyle != "bald" || headstyle != "parted hair" )
But it also had given the same mistake. The program compiles BUT; even if I put in the values bald or parted hair the program prints out "wrong input" then exits.
I have a client/server program. My Client process spawns my server process using a `fork()` and `system()` call. The client and the server are meant to communicate to each other through named piped, that is a requirement of my homework. The client and the server are supposed to initially send a message to the other one, through a pipe, to confirm that a connection is made. My issue is that my client is trying to open one of the named pipes before the server has a chance to make it. This doesn't always happen though. Occasionally, it will run fine. Is there some way to synchronize this?
My overall goal is to get a filename and search target from the user, send those to the server through a named pipe. And the server searches for the target and sends info back.
OUTPUT:
Client: PID 2986 - Running on Tue Sep 30 20:59:28 2014 Client: PID 2986 - Enter File Name: largeSampleText.txt Server PID 2988 - Running on Tue Sep 30 20:59:32 2014 Server: PID 2988 - Synchronized to Client.//This means the client-to-server fifo is working There was an error opening serverToClientfifo//This means client couldn't open the server-to-client fifo error is: 2//This means the fifo doesn't exist yet
[Code] ....
CORRECT OUTPUT:
Client: PID 2542 - Running on Tue Sep 30 20:58:44 2014 Client: PID 2542 - Enter File Name: largeSampleText.txt Server PID 2557 - Running on Tue Sep 30 20:58:54 2014 Server: PID 2557 - Synchronized to Client.
[Code] ....
RELEVANT CLIENT CODE:
int main() { char requestedFileName[1024]; //Get initial information on the client pid_t clientPID = getpid(); time_t currentTime = time(0); char* stringTime= ctime(¤tTime);
[Code] ....
I tried creating both of my fifos in my client and my output changed to this
Client: PID 3150 - Running on Tue Sep 30 21:23:17 2014 Client: PID 3150 - Enter File Name: largeSampleText.txt Client: PID 3150 - Enter Target: Server PID 3153 - Running on Tue Sep 30 21:23:21 2014 was Client: PID 3150 - Input File >>>largeSampleText.txt<<< Client: PID 3150 - Target >>>was<<< Client: PID 3150 - Synchronized to Server Server received unexpected connection message Message: was Terminating
So It appears like the client went ahead and put `requestedFileName` and`requestedTarget`into the pipe and the server read out `requestedTarget` instead of the connection message. Not sure why though
I have a problem with creating a process and waiting until the main window of the new process was shown. I thought I can wait for it with
WaitForInputIdle(pi.hp,INFINITE);
But when the function returns, the handle of the main window of the new process is not available. If I include also a ::Sleep(), the new window is available. Sleep is a bad solution. How can I do it?
Why is it that the program doesn't stop for me to see the output? Here is my code:
// accessing mapped values #include <iostream> #include <map> #include <string> using namespace std; int main () { char str[] = "This table is a good table, while this book is a good book.There is an umbrella on the table"; int n = strlen( str );
I am trying to get my program to output the name from a file. The user should enter first name "or" last name. and if the user does not type the name from the input file. the get an error message. How do you do it
Is there a good way to slow down program output? usleep and nanosleep don't slow it down enough, delay doesn't work, and sleep keeps freezing my program. I am using Linux since I think this makes a difference in what I have to use.
I am wrapping up a Linux/C programming assignment that requires several small programs for encrypting and decrypting text. There is a bash grading script which will be used to assess the performance of my programs. The script runs fine on my local machine and all of my tests pass, but when I run everything on my University's server via SSH, the script is not behaving the same. I am fairly certain the error exists somewhere in my C code, because no other students are having this issue. The 4 main programs consist of 2 daemons which wait for clients to connect via sockets, and the two clients. There is a daemon/client pair for handling encryption, and another for handling decryption.
And here is a screenshot of what happens with the same files on the remote server:As you can see, in the 4th and 5th tests (where the program's output should read), it's instead showing "ssIgnore this message". In later tests (not pictured) there is another message that reads "ddServer to client message". This text appears nowhere in my code or the grading script, so it must be server-side.
My project involves writing a c program to generate a set of 70 decimal numbers. I want to save the output (these 70 numbers) as a txt file. I tried the following:
1. prt scr of output screen and pasting it in notepad. NOT WORKING 2. going to DOS SHELL and doing the following: c:TCBIN>output.exe>>output.txt NOT WORKING. Text file is generated, but it does not contain output. It just says: illegal command: output.exe
Write a program that reads in ten whole numbers and that output the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the ten numbers just once each and the user can enter them in any order.
Your program should not ask the user to enter the positive numbers and the negative numbers separately. Assume the user will type integer numbers.
this is what i got but it wont run saying there is an error
#include<iostream>; using namespace std; int main() { int count=0; int num; int positive=0; int negative=0;