LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-17-2007, 05:37 AM   #1
kingraja84
LQ Newbie
 
Registered: Aug 2006
Location: India
Distribution: suse,mandriva
Posts: 24

Rep: Reputation: 15
new@programming


hi guys,

I am new to network programming,dealing with sockets(bsd)
I want to know what all other ACTIVE systems present on network.how to code??approach is enough please throw ur ideas

my thought: i will act as client & 'connect' to rest of systems
...every other system should work as server and 'accept'my request
if so
i will make a count of active systems present on network
 
Old 04-17-2007, 06:01 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
define what you mean by "active" and "connect" please...
 
Old 04-17-2007, 06:06 AM   #3
kingraja84
LQ Newbie
 
Registered: Aug 2006
Location: India
Distribution: suse,mandriva
Posts: 24

Original Poster
Rep: Reputation: 15
hi

"connect" is a system call in linux which the client side program uses to connect to a known server
"accept" is also a system call but from server side to hear a request from client.

practical implementation of my code:
In hospital every bed has a patient monitoring system and all the systems r in a local network
every system should know what all other systems r present in the network
 
Old 04-17-2007, 06:15 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
so this isn't a case of just finding all machines on a network, but all instances of a given tcp service listening on a certain port... wouldn't really know much about that to be honest, not without port scanning, which is pretty crude. better off in the Programming forum really, moving it there now.
 
Old 04-17-2007, 07:11 AM   #5
slzckboy
Member
 
Registered: May 2005
Location: uk - Reading
Distribution: slackware 14.2 kernel 4.19.43
Posts: 462

Rep: Reputation: 30
my first thought when reading this was port scanner


will you be trying all well known ports.
or a significant few?

You may want to look at the source code for nmap


doing nmap -sP 192.168.0.0/24 for example

will do a ping scan on every machine on the subnet and then print out the available machines.
This obviously uses an icmp echo requestand I gather from eading the man page for nmap it also sends a tcp packet to port 80 using connect() as well.
 
Old 04-19-2007, 08:08 AM   #6
gjo
Member
 
Registered: Aug 2004
Location: South India
Distribution: Fedora3,Xandros,WinXP
Posts: 53

Rep: Reputation: 15
public class findNo{

public static void main(String a[])
{

String s=a[0];
int OneCount=0;
int ZeroCount=0;
for(int i=0;i<s.length();i++)
{
int j=i+1;
String temp=s.substring(i,j);
if(temp.equals("1"))
{
OneCount++;
}
if(temp.equals("0"))
{
ZeroCount++;
}
}
System.out.println("OneCount ++++++++"+OneCount);
System.out.println("ZeroCount ++++++++"+ZeroCount);
}
}
-----------------------------------

public class StringReverse{

public static void main(String arg[]){

String s=arg[0];
String retun="";
for(int i=0;i<s.length();i++)
{
int j=i+1;
String temp=s.substring(i,j);
retun=temp+retun;
System.out.println("String >>>>>. "+retun);
}
}
}

------------------------------------
import java.util.StringTokenizer;
import java.util.*;
import java.io.*;

public class StringMatching{


public static void main(String a[]) throws IOException {

Vector v=new Vector();
Vector sample=new Vector();
Vector count=new Vector();
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Data : ");
String s=bf.readLine();
// String s="the animal is so big, big animal can run fast so we should take care";
StringTokenizer temp=new StringTokenizer(s," ");

while(temp.hasMoreElements())
{
v.add(temp.nextToken());
}
for(int i=0;i<v.size(); i++)
{
String match1=(String)v.elementAt(i);
if(!sample.contains(match1))
{
sample.add(match1);
System.out.print("the word >>>>"+match1);
int Count=0;
for(int j=0;j<v.size();j++)
{
if(v.elementAt(j).equals(match1))
{
Count++;
}

}
System.out.println(" ---------"+Count);
}
}
}
}

--------------------------------------------------------------


execution:

first compile all:
and run like

java findNo 123101
java StringReverse asdfg
java StringMatching
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between Top Down programming & Bottom up programming minil Programming 1 06-17-2005 02:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration