C# :: How To Multithread Port Scanning App

Jan 24, 2012

I'm creating a small port scanning app which use a port range defined by user.My problem with the code is that I find it not efficient enough meaning that it ping very slow, especially when ports are not responding meaning that I must wait for the timeout before continuing to next port.

I want to make this small app threaded. The problem here is that I'm kind of blank of how to implement threading in my program. This is my code which is a method which does the actual checking, the other part of the code is a simple button with for loop for advancing my port number.

Code:

private void ScanPort(IPAddress address, int port) {
using (TcpClient client = new TcpClient() {
IAsyncResult result = client.BeginConnect(address, port, null, null);

if (result.AsyncWaitHandle.WaitOne((int)nudTimeout.Value, false)) txtDisplay.AppendText("Port: " + port + " is open." + Environment.NewLine);
else txtDisplay.AppendText("Port: " + port + " is closed." + Environment.NewLine);
} }

I have read some basic threading tutorial but I just don't know how to implement this piece of code so I can check ports much faster.

View 3 Replies


ADVERTISEMENT

C++ :: How To Multithread Socket Serve

Feb 19, 2013

I'm having a bit of trouble learning how to multithread a socket server. I have everything working perfectly fine, but it only accepts one client (I would like multiple clients). some sort of example (I have troubles understanding some things, unless its visual).

View 4 Replies View Related

C :: Writing Log File In Multithread Program

Oct 20, 2014

I'm currently finishing writing some small application. I want to be able to log important information about the program execution to a logfile, and I have several questions.

First of all - I'd prefer to make the part that logs information to a file separate from the code I've already written. So, what interface should I expose to the rest of the program? Is one function void log(const char*); enough?

Another thing that came to my mind; my program runs two threads, and I want to be able to write to the log file from both threads, so the question is: Should I make sure that the writing to the file is mutually exclusive?

And if so, whose responsibility is it to make the logging to the file thread-safe? The actual part that does the logging (void log(const char*) for that matter), or the parts of the program that calls log(const char*) ?

And lastly, and probably less importantly, where is it customary to save the logfile? (the user's home folder maybe?)

View 3 Replies View Related

C++ :: Finding Multithread Program Error?

Aug 3, 2013

How do I find an error in a multithreading program (written in C)? I get an address, but when I put it into psp-addr2line, i get

??
??:0

View 2 Replies View Related

C# :: MultiThread Blocking Updates During Read

Oct 6, 2014

I have a class holding my data strcuture:

// Holding real time option data - should be thread safe
public class OptionRTHolder {
ConcurrentDictionary<double, Quates> book_calls;
ConcurrentDictionary<double, Quates> book_puts;
ConcurrentDictionary<double, List<Single_qoute>> transaction_calls;
ConcurrentDictionary<double, List<Single_qoute>> transaction_puts;
ConcurrentDictionary<double, int> volume_calls;
ConcurrentDictionary<double, int> volume_puts;
DateTime curr_time;
}

I get a stream of data messages, that come in order, each message carries a time and data. I have many threads in paralell pulling messages and in turn update the data strucutre as follows:

Quates and volume data are just overrun (new value overrun former values), also thier size and meta data is fixed (they don't grow post init).

Via the list I have a problem, I would want to lock only the list I am working on. so other lists can update in paralell, what I had in mind was to warp the list in order to warp the add/get calls to make it thread safety, this I think will achieve this goal and I would like to get some assertion from this forum if you may.

Here come my real problem, there are points in time I want to read/copy this structure, during this time I want to block all updating threads as I want to freeze structure in time, is that achiveable ? Idea that I had is to use something like aquire that will get a function (update/read) and a flag that will cause a lock when the read is on...something like that.

View 3 Replies View Related

C++ :: Multithread Application - Global Dynamic Array

Nov 18, 2013

Let's have global dynamic array p defined as

volatile int p[];

Let's use it in a multithread application, where every thread can change array's size by

new_p = realloc(p, new_size);
if (!new_p) exit 1;
p = new_p;

For simplify assume that we have no problems with it's size and indexing.

Expression like

int x = p[i];

is unsafe cause thread (1) takes the pointer and (2) add the index. Executing of this thread may be stoped after first step before second step. In this time other thread can realloc the array, which move it to some other place in memory. Executing second step after it will add index to wrong pointer. So we will have segmentation fault.

View 2 Replies View Related

C :: Scanning CSV File And Assigning Variable To It

Dec 26, 2013

How to scan a CSV file and assigned variable to each of the integer scanned in a csv file

an example of the csv file:
0001,40,,10

How do I scan the CSV file and assign 0001 to variable student id, the 40 to variable module 01,the 1 without input entered to module02 and 10 to module03

View 6 Replies View Related

C :: Scanning 2 Strings In Same Scanf Call

Nov 20, 2013

Somehow only str2 is successfully scanned and str1 is not printed

Code:

printf("
Please enter two times in this way xx.xx xx.xx now ");
scanf("%s%s", str1, str2);
printf("
%s - %s:
", str1, str2)); result : - str2:

View 3 Replies View Related

C :: Scanning Characters Into A Multidimensional Array

Mar 19, 2014

I have initialized a multidimensional array eg char fruit[5][10]...Then I would need to read in 3 words with spaces in between from user and store in fruit[5][10] e.g "pear apple orange"

The thing is that after typing orange, when I press Enter it still prompts me to enter more characters. How can I end the scanning of characters after orange ?

View 4 Replies View Related

C :: Scanning Equations / Functions Into Program

Nov 15, 2014

I have to make a numerical integration program, how I can write my code so that the user is able to write their own function that they want to integrate?

E.g. they would see the message: 'please enter your function' and would be able to write whatever they wanted e.g. 'x +5' then this would then be integrated by the program.

I have already written a program that can integrate a known function but would prefer that the user could choose their own.

View 2 Replies View Related

C/C++ :: Scanning CSV File Into Array Of Structs

Mar 18, 2015

I need to scan a .csv file that contains the following info:

programming,03,60,141,01,W,2015
programming,03,60,141,30,W,2015
Algebra,03,62,102,02,S,2013
Religion,08,98,938,20,F,2014

So i made a struct:

typedef struct CourseInfo {
int courseID;
char courseName[50];
char courseCode[13];
char term[7];
} courseinfo;

Where course code is the 4 numbers after the name together and the term is the letter and year in the last two pieces of info. I got this to work:

int main() {
FILE *p;
p = fopen("input.csv", "r+");
if(p == NULL) {
puts("The file could not be opened");

[Code] ......

But lets say i dont know how many lines i have in my file and i want to count them and then use that size for my array so i tried this by:

int main() {
FILE *p;
int lines = 1;
char ch;
p = fopen("input.csv", "r+");
if(p == NULL) {

[Code] .....

But the second program is not working for unknown reasons. I do not get any errors but its not scanning the info because when i print the info later on it prints out random symbols.

View 11 Replies View Related

C/C++ :: Error In Scanning Database Names

Feb 13, 2014

I'm working on a program to store student's names, ID, and GPA, but for some reason the first and last name of the student are copied into every name of the database array once I scan them, regardless of whether or not add_student even runs.

typedef struct{
char *f_name;
char *l_name;
int stud_id;
double gpa;
} student_t;
int add_student(student_t db[], char fname[], char lname[], int iden, double grade, int db_size){
int i, error;

[Code] ....

For example, if I type "a Adam Johnson 1234 4.00" it'll add the first student with name Adam Johnson. However, if I try to add another student named "Kyle Walker", it overwrites "Adam Johnson" with "Kyle Walker" as soon as the names are scanned.

View 3 Replies View Related

C :: Scanning A File With Words And Int / Float Numbers

Dec 1, 2013

scanning a file with both words and INT's/Float numbers. This is the file data here.

15 25 200
3 10
17.99 22.99 109.99
100 2 4
5.99 99.99 20.00 49.99
10 10 10 10 10 10 10 10 10 10
3.99 5.99 7.99 8.00 5.00 5.00 5.00 6.00 7.00 9.99

[Code]...

What I'm focused on is reading in the first three numbers which I already have with fscanf and then reading in BUY TICKET with the digit afterwards. My problem is that I don't know how to reach that part of the file without scanning in something I don't want to. Also, how would I scan the number after scanning BUY TICKET? Would it be something like using %s and %d right afterwards?

View 4 Replies View Related

C :: Scanning 2 Dimensional Array For Duplicate Values

Mar 26, 2013

I am trying to scan a 2 dimensional array to see if there are any duplicates within a row or column; i.e. the concept of a sudoku game.how to scan a row or column one at a time.

View 1 Replies View Related

C++ :: Scanning A Header File To Save Image Data

Jun 11, 2013

I'm trying to read from a header file to take the image dimensions and other variables but I don't understand how to iterate through the "key" so it saves each line.

This is what the header file will always look like:

!INTERFILE :=
!imaging modality := nucmed
!version of keys := 3.3
;
!GENERAL DATA :=

[Code].....

Ideally it would just skip the keys that aren't wanted and keep moving through the lines. Should there be a for loop for the key (and if so, how does that work with pointers?) or should this method just be scratched...

View 6 Replies View Related

C :: Scanning Words Into Binary Search Tree - No Stack Error Diving Seg Fault

Apr 2, 2013

This is the first time I have encountered a "no stack." error giving me a seg fault. Anyhow, I am scanning words into a binary search tree and it is giving me a seg fault.

Here is the file (words.txt):
4
bravo
alpha
gamma
delta

Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

typedef struct node_t{
char *word;
struct node_t *left;
struct node_t *right;

[Code] .....

View 5 Replies View Related

C :: Port Mixer From OSS To ALSA

Jan 27, 2013

I'm new in c programming and my requirement is as follows. I make a code for oss mixer and now when new systems, throwing the OSS, and there is no /dev/mixer I want to port my code to alsa but my skills are minimal.

Code:
static int mixer_fd = -1, mixer_src = -1;
static char *devices[] = SOUND_DEVICE_NAMES;
int mixer_init(char *mixer_device, char *mixer_source) {
int i;

mixer_src = -1;
for (i=0;i<SOUND_MIXER_NRDEVICES;i++)
if (strcmp(mixer_source, devices[i]) == 0)

[Code] ....

Coexistance with OSS would be nice, so both could be used depending on users choice. Perhaps: if this first
part of the mixer name is a valid device file, try OSS, otherwise try ALSA?

View 1 Replies View Related

C :: Parallel Port Programming - On / Off LED

Sep 9, 2014

I try to ON and OFF the LED's via parallel port. I connect the cathode of LED's with pin number 18 that is ground and anode of each LED is connected through a 1K resistor to pin 2 to 8. I write the following programe

Code:
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#define PORTID 0x378
void main(){
outportb(PORTID,0x00);
getch()
}

But when i connect the LEDS to the parallel port all the LEDS are LIT while i also change the 0x00 to 0xff and so on. But no effect on the LED's.

View 8 Replies View Related

C :: Parallel Port Where To Start

Jan 1, 2014

I started writing in c because I want to control relays with the parallel port, or anything else. Doesn't really matter what I use I just need to know where to start. Trying to send and receive data from the outside world with c programming on a GNU/Linux os? If so any good some what up to date resources online?

View 5 Replies View Related

C++ :: Output Voltage On USB Port

Oct 26, 2013

I am on a project. I have a laptop and It doesn't have a COM port. So what I would like to do is to get a usb to RS232 cable and write a code so to output voltages on usb and measure it on the RS-232 end. Can I vary the output voltage to my needs?

View 2 Replies View Related

C++ :: Port A Pc Game To Android

Jul 10, 2013

How do I port a pc game to android? Do I just include libraries or do I have to rewrite all my code?

View 5 Replies View Related

C/C++ :: How To Write To The Parallel Port

Apr 16, 2007

How To write to the parallel port under windows xp using Visual C++ ->MS Studio studio 2005

View 4 Replies View Related

Visual C++ :: COM Port Communication

Nov 30, 2012

How to communicate my COM PORT to my visual c++ ... Means i want to read data from my port and want to show in visual c++ so what to do ...

View 1 Replies View Related

C++ :: Inserting Hex Value And Sending It At Serial Port

Dec 17, 2013

I am trying to convert decimal value 1 to 32 to hex value and insert it at 4th pos of char array and send it as hex value at the serial port .

My issue is it is converting to decimal to hex value but when it sends, it treat the converted hex value as char and sends it equivalent hex value.

For example

if decimal =1 then its hex = 1.
so , writebuffer[3] =1

But when we send whole writebuffer through send function, it treat this 1 as char and sends its hex value as 31. how to send its hex value.

unsigned int i=0;
char hex[3];
unsigned char hexunsigned[3];
unsigned int dec;
do {
unsigned char writebuffer[8] ={0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

[Code] ....

The send function is

void serial::send(unsigned char data[], DWORD noOfByte) {
DWORD dwBytesWrite;
WriteFile(serialHandle, data, noOfByte, &dwBytesWrite, NULL);
}

View 2 Replies View Related

C/C++ :: Sending Data To USB Port In Ubuntu?

Apr 21, 2014

How to send a keystroke or a mouse event to another running process in Ubuntu? I want to write a C program that reads data from the USB port sent by AVR Micro Controller board continuously.In response to that it checks the data received and sends a command to another process running on the computer? Example,when the program reads 101 from the USB port it sends left mouse button down to the VLC media player window that is currently running?

View 1 Replies View Related

Visual C++ :: Using The Same Port For 2 UDP Multicast Groups?

Jun 20, 2014

I habe a program, that can send and receive UDP Multicast telegrams. When I open the socket then I bind my multicast group address and the local port to a specified networkcard (our PC has 2 network cards). Now I have a special constellation:

Our PC has 2 network cards. Multicast group 1 shall use card 1 and group shall use card 2. As long as both groups use different local ports it works fine. But when both group want to use the same port number then I can receive and send telegrams only through the first group that was created. For the second one I don't even get a FD_READ event at all.

Code:
SrvAddr.sin_family = AF_INET;
SrvAddr.sin_port = htons( (WORD) nLocalPort );
SrvAddr.sin_addr.s_addr = inet_addr(strOwnIpAddress); // bind multicast group socket to a specified networkcard
// If bind socket to port failed
if( bind( hSocket,

[Code] .....

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved