Sponsored Content
Top Forums Shell Programming and Scripting Listening on port for incoming data? Post 46482 by photon on Friday 16th of January 2004 05:48:08 PM
Old 01-16-2004
In Java you would do something like this:

Code:
public class HTTPServer { 
  public static void main(String a[]) throws Exception { 
  final int httpd = 80; 

  ServerSocket ssock = new ServerSocket(httpd); 
  System.out.println("have opened port 80 locally"); 

  Socket sock = ssock.accept(); 
  System.out.println("client has made socket connection"); 

  OneConnection client = new OneConnection(sock); 
  String s = client.getRequest(); 
  } 
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl Script Listening On A TCP Port

Hi, Im programming a perl script which will act as a daemon listening on a tcp port (2323) and will take (<stdin>) from the client (im going to use telnet) and run the arguments from (<stdin>) against an program already on the server, which is used to list books in the library at uni. So far... (1 Reply)
Discussion started by: emcb
1 Replies

2. IP Networking

port not listening..

Hi.. I am using HPux11.0 i want to know if server not listening to a tcp port what should we do to resolve the problem.... in /etc/services tcp port 7108/tcp is mentioned for some perticular application.. while starting that application error is coming could not establish listening address... (1 Reply)
Discussion started by: Prafulla
1 Replies

3. Linux

VNC Server http listening port

Hi All, I'm running RH 9.0 on a PII box with 160MB RAM. Just downloaded RealVNC X86 Linux (version 3.3.7). How can I get the HTTP listening port up ? Thanks, KENT (6 Replies)
Discussion started by: kxchen_home
6 Replies

4. Programming

rlogin/rsh incoming port

Hi all, In need to know why my sample code below that connect to a rlogind (513) fails, but original unix rlogin does not ? (.rhosts is verified to be correct) I heard rlogin/rsh bind to a reserved port before connecting to the rlogin server. what are they ??? s = socket(AF_INET,... (1 Reply)
Discussion started by: andryk
1 Replies

5. AIX

Get CDE/dtlogin to stop listening on port 6000

Hi all, can anyone help me with this? I'm running AIX 5L v5.3 base and installed CDE is 1.0. I've seen recommendations to add "-nolisten tcp" to the args for X but anytime I try that it simply fails to start. I've tried adding it as an arg to /usr/dt/config/Xservers as well as trying to add it... (0 Replies)
Discussion started by: AIXNewbie
0 Replies

6. Shell Programming and Scripting

Find file that maps to a listening port

On my VPS server I have a port that is open and is listening for a 'status' command when you connect to it to like so... $ telnet host 1900 Trying host... Connected to host. Escape character is '^]'. status QMAIL;OK APACHE;OK HTTPD;OK CRON;OK Wondering if what command I can attempt... (2 Replies)
Discussion started by: phpfreak
2 Replies

7. Cybersecurity

Listening to port when no IP address is assigned

Hi Pals Consider a case where the network interface is there and it is connected to a network. Only thing left here is I need to set a static ip/ip though dhcp (though ifconfig) I heard that it is possible to listen even if the ip address is not set. So is there any possibility of an attack over... (1 Reply)
Discussion started by: sreejithc
1 Replies

8. HP-UX

how to check remote server port listening from application.

Hi, I have an application running on HP-UX, from this application I need to findout if the port number. lets say 7890,7891, 7892 are listening on the remote server running on HP-UX. Is there any way of doing it using "system()" function or any other? I noticed that nmap, netcat are not... (0 Replies)
Discussion started by: einsteinBrain
0 Replies

9. IP Networking

How to find if remote n/w port is listening on HP-UX from the binary

Hi, I have an executable running on HP-UX, from this executable I need to findout if the portnumber. lets say 7890,7891, 7892 are listening on the remote server running on HP-UX. I can do it by creating socket, connect etc. But is there any other way of doing it using "system()" function or... (3 Replies)
Discussion started by: einsteinBrain
3 Replies

10. AIX

Rpcbind Listening on a Non-Standard Port

Hello, I was trying to find information about below rpcbind issue and how can I fix it so that, it wont happen again. Below is the one of the vulnerability from my security team, RPC service name: portmapper service protocal: udp Portmapper found at: 327xx service port: 327xx ... (2 Replies)
Discussion started by: system.engineer
2 Replies
FBB::ServerSocket(3bobcat)					   Server Socket					FBB::ServerSocket(3bobcat)

NAME
FBB::ServerSocket - Server socket accepting Internet connection requests SYNOPSIS
#include <bobcat/serversocket> Linking option: -lbobcat DESCRIPTION
An FBB::ServerSocket may be constructed to listen for connection requests from the Internet or from the local host. Connection requests may be accepted in either blocking or non-blocking modes. When a connection is accepted a socket is returned which may be used to read informa- tion from or write information to the client that requested the connection. The socket that is made available is a file descriptor which may be used to initialize a std::istream and/or std::ostream. The std::istream is used to read information from the client process; the std::ostream is used to send information to the client process. Since a socket may be considered a file descriptor the avaiable FBB::IFd- Stream, FBB::IFdStreamBuf, FBB::OFdStream, and FBB::OFdStreamBuf classes may be used profitably here. Note that having available a socket does not mean that this defines the communication protocol. It is (still) the responsibility of the programmer to comply with an existing protocol or to implement a tailor-made protocol. The latter situation implies that the sequence of input- and output operations is defined by the programmer. NAMESPACE
FBB All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB. INHERITS FROM
FBB::SocketBase CONSTRUCTOR
o ServerSocket(size_t port): This constructor initializes an FBB::ServerSocket object, which will listen for connections at the specified port. The construction of the socket does not mean that the FBB::ServerSocket object is actually listening for connections. To start listening, the member listen() should be used. The copy constructor is not available. MEMBER FUNCTIONS
All members of FBB::SocketBase (and thus of FBB::InetAddress) are available, as FBB::ServerSocket inherits from FBB::SocketBase. o void listen(size_t backlog = 5, bool blocking = true): The listen() member defines the way the FBB::ServerSocket will listen for clients requesting a connection. It can be used only once with a FBB::ServerSocket. An FBB::Errno object is thrown if listening fails, if the constructor could not create a socket, or if the SocketBase base class could not properly be constructed. The listen() member's backlog parameter defines the size of the FBB::ServerSocket's internal queue in which connection requests may be stored waiting for their turn to be serviced. When backlog requests are waiting and another request arrives, then that request is lost. The member's second parameter, blocking, is used to control the blocking mode. By default, blocking is used, and listen() will wait until a connection is established. This is ok in situations where clients connect infrquently and for relatively short time inter- vals. Otherwise, in more complex programs, an FBB::Selector object can be used to sense input on the server socket and/or on various client sockets. o SocketBase accept(): The accept() member returns an FBB::SocketBase object containing information about the client whose connection request was accepted. The FBB::SocketBase object's socket value may be used to initialize streams that can be used to communicate with the client. In more complex programs the FBB::SocketBase could be passed to a class derived from FBB::Fork, handling the communication with the child as a separate (child) process. EXAMPLE
See also the clientsocket(3bobcat) example. #include <iostream> #include <bobcat/serversocket> #include <bobcat/ifdstream> #include <bobcat/ofdstream> #include <bobcat/a2x> using namespace std; using namespace FBB; int main(int argc, char **argv) try { if (argc == 1) { cerr << "Provide server port number "; return 1; } size_t portnr = A2x(argv[1]); ServerSocket server(portnr); cerr << "server listens on port " << argv[1] << endl; cerr << "serversocket returns: " << "address = " << server.dottedDecimalAddress() << " " "port = " << server.port() << endl; int fd = server.socket(); // open the socket's descriptor cout << "File descriptor of the socket is " << fd << " " "The server terminates when it receives a " "single `q' on a line " "A connection is terminated when no input " "is received anymore. " "Then another connection is possible" << endl; server.listen(); // listen in blocking mode while (true) { SocketBase fdb = server.accept(); int fd = fdb.socket(); cerr << "Client FD = " << fd << ", " << endl << "address = " << fdb.dottedDecimalAddress() << ", " << endl << "communication through port " << fdb.port() << endl; IFdStream in(fd); // stream to read from client OFdStream out(fd); // stream to write to client string cmd; while (getline(in, cmd)) { cout << "Got: " << cmd << endl; out << "Got: " << cmd << " " << endl; if (cmd[0] == 'q') return 0; } cout << "Ready for another connection "; } } catch (Errno const &err) { cerr << err.what() << endl << "Server socket on port " << argv[1] << " can't be opened" << endl; return -1; } FILES
bobcat/serversocket - defines the class interface SEE ALSO
bobcat(7), clientsocket(3bobcat), fork(3bobcat), ifdstream(3bobcat), ifdstreambuf(3bobcat), inetaddress(3bobcat), localserversocket(3bob- cat), ofdstream(3bobcat), ofdstream(3bobcat), select(2), selector(3bobcat), socketbase(3bobcat) BUGS
None Reported. DISTRIBUTION FILES
o bobcat_3.01.00-x.dsc: detached signature; o bobcat_3.01.00-x.tar.gz: source archive; o bobcat_3.01.00-x_i386.changes: change log; o libbobcat1_3.01.00-x_*.deb: debian package holding the libraries; o libbobcat1-dev_3.01.00-x_*.deb: debian package holding the libraries, headers and manual pages; o http://sourceforge.net/projects/bobcat: public archive location; BOBCAT
Bobcat is an acronym of `Brokken's Own Base Classes And Templates'. COPYRIGHT
This is free software, distributed under the terms of the GNU General Public License (GPL). AUTHOR
Frank B. Brokken (f.b.brokken@rug.nl). libbobcat1-dev_3.01.00-x.tar.gz 2005-2012 FBB::ServerSocket(3bobcat)
All times are GMT -4. The time now is 01:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy