f



bugs in client\server program - can't connect to remote server #2

hello!

I have a client/server program in which client lets user input two
numbers and the server adds the numbers and returns the sum to client.

the problems I am having are:

1. client is not able to connect to remote server. it is only
connecting to local host.

2. if a string seperated by "non-numeric" characters (e.g. 34a2dd) is
sent, both client and server throw an uncaught exception. i need to
fix the client or server or both and give useful feedback to the user.
i need to do the error checking of user i/p so that user enters only
integers seperated by whitespace.

I am attaching my code.
I am new to java and probably don't know much.
'shall greatly appreciate your help.

thanks in advance,
siddharth

code:

// usage: java TCPAdditionServer3 <port number>
// default port is 7777
// connection to be closed by client
// this server handles only one connection

import java.io.*;
import java.net.*;
import java.lang.*;
import java.util.*;

class TCPAdditionServer3{
public static void main(String[] args)throws Exception{
String clientSentence,capitalizedSentence;
int sum=0;
String sumString = "";
InetAddress serverAddress;
int portNumber = 7777;
Socket connectionSocket = null;

try {
portNumber = Integer.parseInt(args[0]);
}
catch (Exception e) {
System.out.println(" port = 7777 (default)");
portNumber = 7777;
}

// create welcoming socket at port number specified by user or
7777 if no choice is specified by user
ServerSocket welcomeSocket=new ServerSocket(portNumber);

//server infinite loop
while(true){
try {
// wait, on welcoming socket for contact by
client
connectionSocket=welcomeSocket.accept();
} catch (IOException e) {
System.out.println("Accept failed:");
System.exit(-1);
}

// create input stream, attached to socket
BufferedReader inFromClient=new BufferedReader(new
InputStreamReader(connectionSocket.getInputStream()));
// create output stream, attached to socket
DataOutputStream outToClient=new
DataOutputStream(connectionSocket.getOutputStream());

// read in line from socket
clientSentence=inFromClient.readLine();

StringTokenizer st= new StringTokenizer(clientSentence);
while(st.hasMoreTokens()) {
sum += Integer.parseInt(st.nextToken());
}

System.out.println("Waiting for connections on port " +
connectionSocket.getLocalPort() + " ... ");
System.out.println("Received connection from " +
connectionSocket.getInetAddress() + ":" +
connectionSocket.getLocalPort());

sumString = Integer.toString(sum);
clientSentence = " ";
capitalizedSentence = clientSentence  + sumString + "\n";

//write out line to socket
outToClient.writeBytes(capitalizedSentence);

//connection closed by client
try {
connectionSocket.close();
System.out.println("Connection closed by client");
}
catch (IOException e) {
System.out.println(e);
}

}
}

}

code:

// usage: java TCPAdditionClient3 <server> <port>
// default port is 7777

/**
* TCPAdditionClient1.java
*
*  @author Siddharth Jain
* @version 3.0
*/

/** Client Code */

import java.io.*;
import java.net.*;

/** this is the main class */
class TCPAdditionClient3{
public static void main(String[] args)throws Exception{

String sentence,sentc,portNumberString;
int portNumber= 7777;
String hostName = "localhost";
String modifiedSentence;
InetAddress clientAddress;
/** create input stream */
BufferedReader inFromUser1=new BufferedReader(new
InputStreamReader(System.in));

/** read arguments */
if(args.length == 2) {
hostName = args[0];
try {
portNumber = Integer.parseInt(args[1]);
System.out.println("client user i/p port number " +
portNumber);
}
catch (Exception e) {
System.out.println(" server port = 7777 (default)");
portNumber = 7777;
}
}

/** connect to server */
try{
/** create client socket, connect to server */
Socket clientSocket=new Socket(hostName,portNumber);

if (clientSocket.isConnected()== true);
{
System.out.println("Connecting to Server " +
clientSocket.getInetAddress() + ":" + clientSocket.getPort() + "..." +
"Connected");
}

/** create output stream attached to socket */
DataOutputStream outToServer=new
DataOutputStream(clientSocket.getOutputStream());
/** create input stream attached to socket */
BufferedReader inFromServer=new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));

System.out.println();
System.out.println("Enter a string of integers seperated by
non-numeric characters:");

sentence = inFromUser1.readLine();
/**send line to server */
outToServer.writeBytes(sentence+"\n");
/** read line from server */
modifiedSentence=inFromServer.readLine();
System.out.println("From Server-----> The Sum
is:"+modifiedSentence);

try {
clientSocket.close();
}
catch(IOException e) {
System.out.println(e);
}

} catch(UnknownHostException e) {
System.err.println(" Don't know about host: ");
System.exit(1);
} catch(IOException e) {
System.err.println(" Couldn't get I/O for the connection");
System.exit(1);
   }

   }
}

0
sidhjn (5)
12/3/2004 4:06:57 PM
comp.lang.java.programmer 52711 articles. 1 followers. Post Follow

0 Replies
849 Views

Similar Articles

[PageSpeed] 27

Reply:

Similar Artilces:

Server to server = Server client to server?
For a server to server connection, is the connecting server considered as a client of the accepting server or is it not? I have the following classes: Connection <--- base class of the following two ClientConnection <--- client ServerConnection <--- server ServerClientConnection <--- server as a client of another server. But then I came across something that states "A client is anything connected to a server that is not another client". Comments please... Just remember! Server ( programm ) is always listening a connections!!! - wrote: &g...

FM Server 5.5
Hello, Still trying to get this client connected. I posted the questions below two weeks ago, but got no response, so I'm adding them here for reference. synopsis: FM 5.5 server on Win2000, FM 6.0 client on Windows98 (i think - could be Win2k) > FM Server 5.5 serves 8 to 10 clients. 2 clients are Mac, the rest > PC's, Win98 and Win2000. > 5 clients have FM 5.5, 3 have 6.0 > There are two database solutions in the server folder, defined by > filenames. Each solution has 18 files, so there are 36 files being > served. I tried a 'can opener' script. The can ope...

Some people tell that at present, most web hosting servers support all kinds of programming language, some people tell me that many web hosting server don't support Java, What is the truth?
Is Java popular supported by web hosting servers? On Mon, 5 May 2008 19:33:37 -0700 (PDT), Erwin Moller <hi.steven.tu@gmail.com> wrote, quoted or indirectly quoted someone who said : >Is Java popular supported by web hosting servers? see http://mindprod.com/jgloss/ispvendors.html -- Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com Erwin Moller wrote: > Is Java popular supported by web hosting servers? We just started a Java web hosting service, address below. -- Dave Miller Strategic Services Group, Inc. http://www.cheap-jsp-hosting.com/ Dave Miller...

10.2 "connect to server" won't stay connected
Using go->connect to server seems to work on occasion, not sure if my server is moody, but I can connect sometimes. Regardless, if my 10.2 G4 goes to sleep, my server connection is gone and I have to reconnect. Can this connection remain permanent? Does this seem to be a server issue and not a Mac issue? thanks, anthony In article <f0a79190.0402271255.4a2dd4e6@posting.google.com>, ajc1961@yahoo.com (anthony) wrote: > Using go->connect to server seems to work on occasion, not sure if my > server is moody, but I can connect sometimes. Regardless, if my 10.2 > G4 goes...

Client-Server ( Client starting server remotely )
I'm writing a client-server app. Client controls Server which in turn configures and controls a bunch of hardware. I want to be able to start the server from my client. Now in C/C++ one could simply run the appropriate command string through a standard "system()" call which is relatively simple. JAVA on the other hand seems to require something like RMI to do it. Basically a use case for what I want to do is something like: Start Client GUI Enter name of data file Client checks bonafides of data file. Client reads and parses data file bui...

Java JRE (1.4.2)
FamilyNet International Newsgate From: BertieBigBollox@gmail.com David H. Lipman wrote: > From: <BertieBigBollox@gmail.com> > > | > | Like I said, unfortunately, we are forced to use Java JRE v1.4.2 > > Then you are at risk ! > > Like I stated, that version is vulnerable and is actively being Exploited ! > Unfortunately, we're tied to what version of Java the application software that uses it supports. At the moment, they only actively support v1.4.2 although it probably does work with v1.5. This is a pretty common problem with software integration. I remember having to use Solaris 2.5.1 for years even though Solaris 2.8 was available just because our software worked on 2.5.1 and was never tested on 2.8. However, with regards to being exploited - this is a closed secure network so there shouldn't be a problem with hacking etc. FamilyNet <> Internet Gated Mail http://www.familynet-international.org ...

remote printing between sco server, server won't come up!
We've got a couple of SCO 5.0.6 servers and on some of then are serial printers connected. We won't to share these using lpd. i've installed it like it should be done according by SCO! but when i put a printjob in the queue it stays there, and it wont't get printed this is what i get. # rlpstat remote_printer local.servername: waiting for remote.servername to come up req-id ... the printers are all accepting and enabled. I've got the feeling it is something stupid are just a deamon that aint running! could you advise me how to get it printing? thanks Marco &qu...

OS X 10.6.2 / Eudora 6.2.4
Hi, I have never done this before and I am just about desperate to get eudora functioning again. I have used eudora for @15 years and it suits my needs perfectly. Although I have had issues in the past something occurred in mid-November which I have not been able to resolve and, in the process, messed up some settings. No one that I know knows how to correct this so I am hoping one of you might. So, around mid-November I suddenly was not able to send an e-mail using eudora. One of the error messages I keep getting is "Server not responding. 706". Another is "...

ssh client gets to server, but doesn't connect...?
Been running SuSE 8.0 (kernel 2.2 I think?!) on a Pentium II 400mhz for YEARS and it finally died. I used to port forward from my firewall from an obscure port (we'll say 99) to the SSH port, port 22, and it worked great. But after my SuSE 8.0 machine died, I decided it was time to "modernize" so I installed SuSE 10.1 64-bit on a brand new machine. Now, I can't connect to the sshd from the outside any more. I'm using essentially the same sshd_config file, and using tcpdump w/o promiscuious mode, I can see the SSH traffic hitting the eth0 interface. I can also see the port forwarding through the firewall (from 99 -> 22 and then of course tcpdump is watching port 22), and I can see the traffic all the way through. Nothing shows up in syslog however either. But on the machine, it seems sshd itself isn't seeing the traffic. NetFilter is NOT on, there is nothing blocking the traffic at the machine level, sshd just seems not to answer? I tried setting the ListenAddress, as I have two NICs in this machine, whereas my 8.0 machine only had one (actually, I think even it had two). For the life of me I can't figure it out. Nothing in the sshd_config file (attached) seems to stare out at me. Was just wondering if anyone had any ideas. I had a similar issue at work where I installed SuSE 10.0, and invited a colleage to ssh into the box and he couldn't, but on the local LAN, I could. Same here as well, BTW. On the local LAN (192.168.0.0/24...

Client Server/Client Server Programmer(Welfare Reporting and Tracking System)
Personnel Title: Client Server/Client Server Programmer Assignment or Project Name: Welfare Reporting and Tracking System Number of Positions: 1 Expected Duration of Assignment: 12 months Rate: Open Location: New York State Mandatory Requirements Note: Candidates not meeting the following mandatory requirements as contained in the RFP will not be considered for further evaluation: 1. Associate's Degree (Pass/Fail) 2. Minimum of 2 years experience Micro Focus COBOL (Pass/Fail) 3. Minimum of 2 years experience in Oracle 9i, Oracle 10g, or higher (Pass/Fai...

what is "Cannot assign requested address
Hi guys, I once wrote a server program, it prefer a long connection, I mean, accept once then loop read/write, but if client only give once read/write, it can close the client fd no problem. Then I wrote a client a program but it prefer short connection, that is, connect/write/read/close, then the client loop do connect/read/write about 1 millioin times. I found after about 28231 connection, the client exeception with error "Cannot assign requested address - connect(2)". if I change the client model to long connection, or I change the server model to process only short conne...

Client connection SHARED don't use server SQLNET.ORA
Hi ! I need (maybe) a simple help.. I test that when i use a client connection of type SHARED, i can't trace that from server (by TRACE sqlnet.ora parameter); instead i can trace it when i use DEDICATED connection. What's this ? Thanks for attention. Bye Alex System description: XP Client with Oracle 9.0.1.0 -> Aix Server with Oracle 9.2.0.5 On 2 Jul 2004 08:21:10 -0700, crapisi@tiscali.it (@lex) wrote: >Hi ! > >I need (maybe) a simple help.. > >I test that when i use a client connection of type SHARED, i can't >trace that from server (by TRACE sqlnet.ora...

[ace-users] Client doesn't received data from the Server #2
ACE VERSION: 5.3.3 HOST MACHINE and OPERATING SYSTEM (cygwin( 2003.02.26) on Windows XP Pro on i686 system) $ uname -a CYGWIN_NT-5.1 paradise 1.3.20(0.73/3/2) 2003-02-08 12:10 i686 unknown unknown Cygwin COMPILER NAME AND VERSION (AND PATCHLEVEL): gcc version 3.2 20020927 (prerelease) CONTENTS OF $ACE_ROOT/ace/config.h: -> #include "ace/config-cygwin32.h" CONTENTS OF $ACE_ROOT/include/makeinclude/platform_macros.GNU (unless include $(ACE_ROOT)/include/makeinclude/platform_cygwin32.GNU AREA/CLASS/EXAMPLE AFFECTED: Examples ...

my credentionls doesn't save in App server or Client machine.. #2
hey Gys.. I've problems my linux kerberos server. My kerberos server have installed in my computer and applications server is another network in my LAN. I've configured a web server with kerberos 5. My /etc/krb.conf : [logging] default = FILE:/var/log/krb5libs.log kdc = FILE:/var/log/krb5kdc.log admin_server = FILE:/var/log/kadmind.log [libdefaults] default_realm = KRB.MNETPLUS.COM <http://krb.mnetplus.com/> default_tkt_enctypes = des3-hmac-sha1 des-cbc-crc default_tgs_enctypes = des3-hmac-sha1 des-cbc-crc dns_lookup_realm = false dns_lookup_kdc = false [realms] KRB.MNETPLUS.COM <http://krb.mnetplus.com/> = { kdc = krb.mnetplus.com:88 admin_server = krb.mnetplus.com:749 default_domain = krb.mnetplus.com } [domain_realm] .krb.mnetplus.com = KRB.MNETPLUS.COM <http://krb.mnetplus.com/> krb.mnetplus.com = KRB.MNETPLUS.COM <http://krb.mnetplus.com/> [kdc] profile = /usr/local/var/krb5kdc/kdc.conf [appdefaults] kinit = { forwardable = true } telnetd = { forwardable = true } klogind = { forwardable = true } pam = { debug = false ticket_lifetime = 36000 renew_lifetime = 36000 forwardable = true krb4_convert = false } My /usr/local/var/krb5kdc/kdc.conf [kdcdefaults] kdc_ports = 750,88 [realms] KRB.MNETPLUS.COM <http://krb.mnetplus.com/> = { profile = /etc/krb5.conf database_name = /usr/local/var/krb5kdc/principal admin_database_name = /usr/local/va...

Entreprise Manager error message: "[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user '#####'. The user is not associated with a trusted SQL Server connection.(28000,18452)"
Can anyone give a quick description of the meaning of this message and what needs to be done to get a connection. I'm running DBArtisan with SQLServer 2000 client SP4 installed. I also get the same message with MS Enterprise Manager so this is coming out of the actual ODBC connection attempt. Thanks in advance! In the future, please do not put part of your message in the subject line. Makes it harder to read. In any case, you're trying to do integrated login and don't have that login set up in the DB. You need to add that login, or change to a SQL Login. -- Greg Moore SQL...

AW: Blocking read to wxSocketBase doesn't block after remote server has gone. #2
Hi Raphael I've written 6 services (wxBase / wxSocket / NT Service) which are basically build the same way (Note: the code is not complete!!!): int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow ) { // declare variables int argc; char **argv; // init library wxApp::CheckBuildOptions(wxBuildOptions()); wxInitializer initializer; if( !initializer ) { return -1; } // break the command line in words wxArrayString args = wxCmdLineParser::ConvertStringToArgs(wxConvertMB2WX(szCmdLi...

Re: Setup Home IIS Server That Doesn't Allow Outside Connections #2
strutsng@gmail.com wrote: > I want to know if ISP SBC block incoming port 80 request from outside? Probably. Most ISPs do block incoming port 80. If you want to run a server, make sure to subscribe to a service that allows it. Steve Sobol, Professional Geek 888-480-4638 PGP: 0xE3AE35ED Company website: http://JustThe.net/ Personal blog, resume, portfolio: http://SteveSobol.com/ E: sjsobol@JustThe.net Snail: 22674 Motnocab Road, Apple Valley, CA 92307 ...

how do I transfer files to remote server logging into remote server's $BASH prompt
I'm a nebie and exhausted working with my ISP trying to securely transfer files to the hosting account. I can log into to using PuTTy and get to a $BASH prompt. From there I can use FTP but then I am ftping from THAt server, not my computer. I have tried WinSCP but I don't have SCP on remote server and don't want to load it on server as I am obviously a novice with */nix commands Any ideas? On Mon, 17 Nov 2003 16:43:51 -0500 NotGiven scrawled this disquisition: > I'm a nebie and exhausted working with my ISP trying to securely transfer > files ...

Web Server connecting to Informix Server #2
I am running an OLTP system with Informix 7.3 IDS on HPUX. We are considering writing some web interfaces to connect to the database. At first we mirrored the database tables to a web server so that no one was ever touching live data. This was relatively easy, just do a nightly export/import to the web server. However, we now wish to create some "updating" web pages that will connect back to the server. On the web server I am using PHP/MySQL/Apache for web development with the Slackware Linux v 9.0 (Linux 2.4.7) distrobution. I have tried multiple times to install the Linux Client-SDK hoping that somehow I could make a ODBC connection back to the Informix server. I have not yet been successful. I found a company that makes an Informix ODBC driver. I was unsucessful at getting it licensed for a 30-day trial. I tried compiling informix libraries into PHP, but ESQL doesn't seem to be compatible with gcc. What is the best way to connect the Linux web server to the HPUX Informix server? Can anyone point me to documentation on how to do this? I would RTM if I could find one. Any tips, links, articles, etc would be appreciated. John Wilson Administrative Systems Specialist Troy School District Information Systems sending to informix-list sending to informix-list ...

Oracle server 9.2.0.1.0, Client 9.2.0.4.0, Red Hat Linux enterprise advanced server 2.1
Hi Everybody, My Database server is running on Red Hat Linux enterprise advanced server 2.1, And my Oracle version is 9.2.0.1.0. My Client mechine also Red Hat Linux enterprise advanced server 2.1 , Oracle client version is 9.2.0.4.0. I am running a web application. Our application is in Magic edeveloper. I connect to Oracle using oracle gateway to my application. My Problem is my application is is becoming slow. I am not able to trace where the problem is. Before our application was running fine. recently i upgraded Oracle client version to 9.2.0.4.0. My Oracle client & server versi...

Connecting to a Server on a Server
I have a chat client that needs to connect to a chat server in order to function. This is for research use so I have access to an academic server named Updraft. For this research, Updraft acts as a central point where all data is accumulated. It would be real nice if I could have all the chat client connect to the chat server that resides on Updraft. I problem I see here is that Updraft uses SSH and the chat clients use IO::Socket::INET. That means that first a user would have to login to Updraft using SSH then the client program creates a socket using IO::Socket::INET. That seems a bit strang...

client server programming #2
hi all I am writing chat application when new request comes to server it will fork and creates a child for that request and parent will wait for next request.Since there is only one accept call after first success it will return.How to do this for n number of requests. If possible plz explain with example On Jan 27, 1:21 am, shiv <vgst...@gmail.com> wrote: > I am writing chat application when new request comes to > server it will fork and creates a child for that request and parent > will wait for next request.Since there is only one accept cal...

RE: Web Server connecting to Informix Server #2
John Assuming you have IDS running on your web server you don't need anything else to communicate between the two engines apart from setting up the sqlhosts, /etc/services and .rhosts (/etc/hosts.equiv) files. You can then update any tables from either engine. (Both databases need to have the same logging state). To make names easier you might want to use synonyms or views. Keith -> -----Original Message----- -> From: Wilson, John [mailto:JWilson3@troy.k12.mi.us] -> Sent: Wednesday, September 03, 2003 5:31 PM -> To: informix-list@iiug.org -> Subject: Web Server connecting to Informix Server -> -> -> -> I am running an OLTP system with Informix 7.3 IDS on HPUX. -> We are considering writing some web interfaces to connect to -> the database. At first we mirrored the database tables to a -> web server so that no one was ever touching live data. This -> was relatively easy, just do a nightly export/import to the -> web server. -> -> However, we now wish to create some "updating" web pages -> that will connect back to the server. On the web server I -> am using PHP/MySQL/Apache for web development with the -> Slackware Linux v 9.0 (Linux 2.4.7) distrobution. -> -> I have tried multiple times to install the Linux Client-SDK -> hoping that somehow I could make a ODBC connection back to -> the Informix server. I have not yet been successful. I ...

windows server not connecting to BIND 9 server #2
Hi: I've got a local subnet (192.16.1.x) that's NAT'd behind a firewall. I've got a BIND 9.2.3 server running on RH9...it's on 192.168.1.200 I've got a Win2K server on 192.168.1.202 The NS is accessible to the outside world. I've set up two views, one for the 192.x.x.x machines and one for the outside world. When I query the NS from another box on the subnet, it correctly resolves the local IPs for various domains. The Win2K server, however, can't seem to get through to the NS. If I set the local NS in the TCP/IP properties and do an nslookup, I get no response...the request times out. If I switch the NS to some public servers outside my subnet, the Win2K server connects fine. Any reason why it won't connect when the NS is set to a 192.x.x.x address? ...

NIS server not responding -- but it isn't the server
here are the symptoms: the solaris 10 x86 box locks up. i can't ping it. this is my desktop machine; i run tripwire on it; the configuration hasn't changed. i notice that there are two nscd running. the messages file says that the NIS server is not responding, but i know that the NIS server is responding to everyone else. so the server isn't the issue. i've been rebooting to force my way in. after the boot msgs end, the messages file first claims the NFS server isn't responding, then the NIS server. these are two different servers and only this machi...

Web resources about - bugs in client\server program - can't connect to remote server #2 - comp.lang.java.programmer

Resources last updated: 3/14/2016 6:10:45 AM