Increasing socket readers in client program
I am trying to connect to multiple Weblogic servers from a single client at
the same time and get the following message:
<Sep 14, 2001 10:21:15 AM CDT> <Warning> <JavaSocketMuxer> <There are: '3'
active
sockets, but the maximum number of socket readers allowed by
theconfiguration is
: '2', you may want alter your configuration.>
How do I change the configuration in my client so I can have more the two
connections.
Thanks,
Jim Anderson
java -Dweblogic.ThreadPoolSize=15 -Dweblogic.ThreadPoolPercentSocketReaders= 75
(means 75% of ThreadPoolSize)
-classpath %classpath%;. etc...
James Anderson wrote:
I am trying to connect to multiple Weblogic servers from a single client at
the same time and get the following message:
<Sep 14, 2001 10:21:15 AM CDT> <Warning> <JavaSocketMuxer> <There are: '3'
active
sockets, but the maximum number of socket readers allowed by
theconfiguration is
: '2', you may want alter your configuration.>
How do I change the configuration in my client so I can have more the two
connections.
Thanks,
Jim Anderson
Similar Messages
-
Increasing max number of socket readers on client
How can you increase the number of socket readers on a client
application which
uses JMS, EJB and talks to multiple WLAS servers.
I get the following message
Muxer> <There are: '3' active sockets, but the maximum number of socket
readers allowed by theconfiguration is: '2', you may want alter your
configuration.>
But I cant find out how to increase the socket readers or better yet can
I use the native IO for Solaris and NT clients??
Try to use the WebItem Parameter "MAX_TEXT_LINES":
<object>
<param name="OWNER" value="SAP_BW"/>
<param name="CMD" value="GET_ITEM"/>
<param name="NAME" value="DOCUMENT_1"/>
<param name="ITEM_CLASS" value="CL_RSR_WWW_ITEM_DOC"/>
<param name="DATA_PROVIDER" value="DATAPROVIDER_1"/>
<b><param name="MAX_TEXT_LINES" value="50"/></b>
ITEM: DOCUMENT_1
</object> -
Socket Based Server/Client Program Help Needed
Alright,
I am making a Client/Server program.
The idea is that, when I run the 'Server' part, it sits and listens for a connection from the Client.
The Client writes a string to the socket, then the server, interprets the command.
This is what I have so far.
The Server:
public static void main(String[] args) {
String clientLine = null;
Socket channel = new Socket();
try {
mainWin window = new mainWin();
window.open();
} catch (Exception e) {
e.printStackTrace();
try{
ServerSocket server = new ServerSocket(8313);
BufferedReader reader = new BufferedReader(new InputStreamReader(channel.getInputStream()));
channel = server.accept();
clientLine = reader.readLine();
doCommand(clientLine);
reader.close();
channel.close();
server.close();
catch(IOException ioe){
System.out.println("I/O Exception occurred while using the server");
}The Client:
public void sendCommand(String command){
PrintStream socketWriter = null;
try{
Socket client = new Socket("127.0.0.1", 8313);
socketWriter = new PrintStream(client.getOutputStream());
socketWriter.println(command);
socketWriter.close();
client.close();
}catch(UnknownHostException uhe){
}catch(IOException ioe){
}When I press the command button, it lags for a second, then does nothing.
Does anyone see the problem?public static void main(String[] args) {
String clientLine = null;
Socket channel = new Socket(); //<-- This is connecting to where? nowhere, so initiate it to null instead.
try {
mainWin window = new mainWin();
window.open();
} catch (Exception e) {
e.printStackTrace();
try{
ServerSocket server = new ServerSocket(8313);
BufferedReader reader = new BufferedReader(new InputStreamReader(channel.getInputStream())); //<-- Getting an input stream from nowhere?
channel = server.accept(); //<-- Perhaps you want to do this before you try to get the input stream from it?
clientLine = reader.readLine();
doCommand(clientLine);
reader.close();
channel.close();
server.close();
catch(IOException ioe){
System.out.println("I/O Exception occurred while using the server");
} -
Increasing Weblogic client Socket Readers etc
How can you increase the number of socket readers on a client
application which
uses JMS, EJB and talks to multiple WLAS servers.
I get the following message
Muxer> <There are: '3' active sockets, but the maximum number of socket
readers allowed by theconfiguration is: '2', you may want alter your
configuration.>
But I cant find out how to increase the socket readers or better yet can
I use the native IO for Solaris and NT clients??Hi,
You can control the number of threads and the precent of socket readers
through the properties: weblogic.ThreadPoolSize and
weblogic.ThreadPoolPercentSocketReaders. You would have to pass them to the
jvm machine at startup for example:
-Dweblogic.ThreadPoolSize=10 -Dweblogic.ThreadPoolPercentSocketReaders=50
Guy
"Larry Presswood" <[email protected]> wrote in message
news:[email protected]..
How can you increase the number of socket readers on a client
application which
uses JMS, EJB and talks to multiple WLAS servers.
I get the following message
Muxer> <There are: '3' active sockets, but the maximum number of socket
readers allowed by theconfiguration is: '2', you may want alter your
configuration.>
But I cant find out how to increase the socket readers or better yet can
I use the native IO for Solaris and NT clients?? -
I'm running a cluster of 3 WL 6.0 servers and when I do a JNDI lookup to run methods
on a remote interface stub on the client side it gives me the following:
<Apr 26, 2001 2:16:34 PM MST> <Warning> <JavaSocketMuxer> <There are: '3' active
sockets, but the maximum number of socket readers allowed by theconfiguration
i
s: '2', you may want alter your configuration.>
I re-ran my client with the two following properties:
-Dweblogic.system.executeThreadCount=5
-Dweblogic.system.percentSocketReaders=60
it still gives me the exception. How do I get this to work properly so I have
as many socket readers as servers?
Thanks in advance.
Thanks,
I had understood this wrong, I was configuring on the server, not the client
application,
it's all working well now.
Cheers
Sioux
"Kumar Allamraju" <[email protected]> wrote in message
news:[email protected]...
> i.e. if percentSocketReaders = 50, and execute Threadcount is 20, 50% of
20 = x?
>
> you will get x percentSocketReaders. You might want to tune this value ,
> according to the above
> formula.
>
>
> Sioux France wrote:
>
> > Hi,
> > I'm getting these errors too. I've enabled native IO, upped the number
of
> > Threads to 20 and the percentage of readers to 50% but I still get the
error
> > about 3 active sockets when I am only allowed 2 in a cluster of 3
servers.
> > Did you resolve this?
> > Thanks
> > Sioux
> >
> > "Kumar Allamraju" <[email protected]> wrote in message
> > news:[email protected]...
> > > The following syntax was correct in 510. , not in 60 anymore.
> > > I would suggest you to increase the execute Thread count & percent
socket
> > readers from
> > > console.
> > >
> > > or else set the following from the command line.
> > > -Dweblogic.ThreadPoolPercentSocketReaders
& -Dweblogic.ThreadPoolSize..
> > (i'm not 100%
> > > sure)
> > > --
> > > Kumar
> > >
> > > "W. Wen" wrote:
> > >
> > > > I'm running a cluster of 3 WL 6.0 servers and when I do a JNDI
lookup to
> > run methods
> > > > on a remote interface stub on the client side it gives me the
following:
> > > >
> > > > <Apr 26, 2001 2:16:34 PM MST> <Warning> <JavaSocketMuxer> <There
are:
> > '3' active
> > > > sockets, but the maximum number of socket readers allowed by
> > theconfiguration
> > > > i
> > > > s: '2', you may want alter your configuration.>
> > > >
> > > > I re-ran my client with the two following properties:
> > > >
> > > > -Dweblogic.system.executeThreadCount=5
> > > > -Dweblogic.system.percentSocketReaders=60
> > > >
> > > > it still gives me the exception. How do I get this to work properly
so I
> > have
> > > > as many socket readers as servers?
> > > >
> > > > Thanks in advance.
> > >
>
-
Error message when access WLS: active sockets and socket readers configuration
Hi,
I got the following error when I tried to access the WLS using a program to get
the mbeans data.
This error happens when I have 3 or more servers running ( 1 admin server, 2 or
more managed servers). With cluster with more than 2 servers running, this error
also occurs.
<Sep 10, 2001 8:35:01 PM CDT> <Warning> <JavaSocketMuxer> <There are: '3' active
sockets, but the maximum number of socket readers allowed by theconfiguration
is: '2', you may want alter your configuration.>
I creased the socket readers from 33% to 66%, but I still got the same error.
I'm using WLS version 6.0 sp2
My configuration is:
Execute Threads = 15,
Socket Readers = 33% or 66%
Does anyone know how to fix this ? I am really appreciate for any suggestions.
thanks,
Kieuthank you, I just found out about setting those sockets using command line options
an hour ago. But thanks a lot.
-Kieu
Kaye Wilcox <[email protected]> wrote:
Kieu,
You could try increasing the number of execute threads, you can do this
via
the admin console on the <server> --> Tuning tab.
See http://edocs.bea.com/wls/docs60/perform/WLSTuning.html#1104317 for
guidelines on setting the thread pool size and the number of socket readers.
Here is a link that talks about socket communication in a cluster
http://edocs.bea.com/wls/docs60/cluster/features.html#1007001. -
Currently using WebLogic 6.1 SP2 on Win NT 4.0 with jdk 1.3.1. 2 servers in a cluster.
The following message is seen.
<ExecuteThread: '10' for queue: 'default'> <> <> <000000> <There are: '7' active
sockets, but the maximum number of socket readers allowed by the configuration
is: '6', you may want to alter your configuration.>
How do we ensure our configuration is correct? Whenever this message is seen and
the servers need to start. If we do not restart them, after a while they will
hang and we need to restart them. Is there any way to resolve this issue? Thanks.Hi,
Thanks for your info on Native IO.
There is a JVM error message thrown when we are trying to do the thread dump.
From the JDK website, we realise it is a bug for jdk 1.3.1. Thanks.
Regards,
Ai Ling
Arunabh Hazarika <[email protected]> wrote:
When native i/o is used, there are a fixed number of threads that are
dedicated to reading
incoming requests from clients. These threads are non-blocking i.e. they
do not block
waiting for data to arrive at a socket. When using Java i/o, the threads
block waiting for
data to arrive at a socket. In this case, if the number of sockets opened
is greater than
the number of threads available to read them, data on the remaining sockets
will remain
unread, until a thread becomes available to read it and response time
will increase. This is
basically what the message means.
It is not surprising that performance has degraded by turning off native
i/o. The message is
not the problem - turning off native i/o is.
I do not recall there being a problem with taking thread dumps with JDK
1.3.1 - what
indicates that the thread dump is not complete?
Arunabh
apple wrote:
Hi Arunabh,
Is this message critical? As we encounter this message, the server'sperformance
is very slow. Without this message, the access to the server is muchfaster. We
will like to know whether we can ignore this message or this messagehas any implication
to our servers.
As for your proposal to enable the native io and take thread dump,we have already
done that. But due to our jdk version used, we are not able to getthe full thread
dump.
Thanks.
Regards,
apple
Arunabh Hazarika <[email protected]> wrote:
To answer your second message first, yes, this message comes when
native
i/o is
disabled. For the first problem, I am not sure how disabling nativeio
would help
resolve a server hang - Please take a thread dump when the serverhangs
with native
i/o enabled and post it here.
Thanks,
Arunabh
apple wrote:
Hi Arunabh,
Our application server will use up the threads very fast and not
releasing
them
after usage, causing our servers to hang once we enable native io.Thus we have
no choice but to disable the native io. Is there any resolution
for
this? Is it
due to we disable native io which cause the following message to
appear?
<ExecuteThread: '10' for queue: 'default'> <> <> <000000> <Thereare:
'7' active
sockets, but the maximum number of socket readers allowed by the
configuration
is: '6', you may want to alter your configuration.>
Thanks for your prompt reply.
Regards,
Apple
Arunabh Hazarika <[email protected]> wrote:
It looks like you have native io disabled. Is there a reason why?
Arunabh
apple wrote:
Currently using WebLogic 6.1 SP2 on Win NT 4.0 with jdk 1.3.1.
2
servers
in a cluster.
The following message is seen.
<ExecuteThread: '10' for queue: 'default'> <> <> <000000> <There
are:
'7' active
sockets, but the maximum number of socket readers allowed by
the
configuration
is: '6', you may want to alter your configuration.>
How do we ensure our configuration is correct? Whenever this
message
is seen and
the servers need to start. If we do not restart them, after a
while
they will
hang and we need to restart them. Is there any way to resolve
this
issue? Thanks. -
Error message on active sockets & socket readers configuration
hi Kieu,
I am having the same problem. Were you able to figure out why you had that
problem and how you resolved that issue. I am seeing slow performance on client
as well. I am assuming this could be the reason for slow performance.
thanks,
Zeeshan.
"Kieu Tram" <[email protected]> wrote:
>
Hi,
I got the following error when I tried to access the WLS using a program
to get
the mbeans data.
This error happens when I have 3 or more servers running ( 1 admin server,
2 or
more managed servers). With cluster with more than 2 servers running,
this error
also occurs.
<Sep 10, 2001 8:35:01 PM CDT> <Warning> <JavaSocketMuxer> <There are:
'3' active
sockets, but the maximum number of socket readers allowed by theconfiguration
is: '2', you may want alter your configuration.>
I creased the socket readers from 33% to 66%, but I still got the same
error.
I'm using WLS version 6.0 sp2
My configuration is:
Execute Threads = 15,
Socket Readers = 33% or 66%
Does anyone know how to fix this ? I am really appreciate for any suggestions.
thanks,
Kieu -
Connection reset when closing the client program.
when closing the client program I get the error message Connection Reset
at ServerThread.run(SeverThread.java:244)
which is the following file
i've marked the 244: on this file on the left of the file.
after this I have the client program which is called Client.java
the error happens when I close the client program and the error is on the serverthread side of the application. Please anyone help out with this one.. Thanks.
//SererThread.java
import java.net.*;
import java.io.*;
import java.util.Date;
import java.util.Calendar;
import javax.swing.*;
public class ServerThread extends Thread {
private Socket socket = null;
String outputStrings = "";
public ServerThread(Socket socket) {
super("ServerThread");
this.socket = socket;
Calendar c = Calendar.getInstance();
int hr = c.get(Calendar.HOUR_OF_DAY);
int hour=hr-1;
int min = c.get(Calendar.MINUTE);
int sec = c.get(Calendar.SECOND);
String timeOfConnect [] = new String[100];
int conCtr = 0;
int curState = 0;
String entries [][] = new String[5][100];
public String getInput(String theInput) {
String sentToClient = null;
Calendar c = Calendar.getInstance();
int hr = c.get(Calendar.HOUR_OF_DAY);
int hour=hr-1;
int min = c.get(Calendar.MINUTE);
int sec = c.get(Calendar.SECOND);
int day = c.get(Calendar.DAY_OF_WEEK);
int month = c.get(Calendar.MONTH);
int year = c.get(Calendar.YEAR);
int pm = c.get(Calendar.PM);
String strHr = Integer.toString(hour);
String strMin = Integer.toString(min);
String theInputSeg = "";
if(theInput!= null)
for(int a=0;a<theInput.length();a++)
char inputCharArray [] = theInput.toCharArray();
if(inputCharArray[a]==';')
theInputSeg = theInput.substring(0,a);
if (curState == 0) {
if(c.PM==1&& hour == 8)
sentToClient = "yes";
curState = 1;
} else if (curState == 1) {
for(int a=0;a<3;a++)
//System.out.println("theInput:" + theInput);
//System.out.println("a:" + entries[0][a]);
//System.out.println("a:" + entries[1][a]);
//if()
if(theInputSeg.equalsIgnoreCase("CUSCarissa_Calton25242526")||theInputSeg.equalsIgnoreCase("CUSSan_Htat27242526")
||theInputSeg.equalsIgnoreCase("CUSSadam_Husien20909990"))
//if(theInput.equalsIgnoreCase(entries[0][a])||theInput.equalsIgnoreCase(entries[1][a]))
System.out.println("buy...");
curState = 0;
sentToClient = "Bye.";
else
System.out.println("buy...!");
curState = 0;
sentToClient = "Hello.";
return sentToClient;
public void run() {
int next = 0;
BufferedWriter bw = null;
byte [] b = null;
BufferedWriter bw1 = null;
try{
//JOptionPane.showMessageDialog(null,"Sizz");
String fileNameStr = "C:\\San Server Data\\cInputCustData.txt";
File f = new File(fileNameStr);
long size = f.length();
b = new byte[(int)size];
FileInputStream fis = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis);
int count = 0, index = 0;
int byteRed = 0;
int sizeInt = (int)size;
while (bis.available() > size-1)//16848 )
bis.read(b,index,(int)size);
//int bytesRead = bis.read(b,index,(int)size2);
//size2 -= count;
//index += count;
//System.out.println( "hello:" + b[index]);
//index++;
//bis should be closed in a finally block.
bis.close() ;
catch(IOException io)
System.out.println("Oh oh io error");
//System.out.println("cInputCustData: \n" + new String(b));
String bStr = new String(b);
char charbStr []= bStr.toCharArray();
String header []= new String[5];
int ctr = 0;
int e = 0;
boolean first = true;
for(int q=0;q<5;q++)
for(int u=0;u<100;u++)
entries[q]= new String("");
//System.out.println("b: " + bStr);
for(int s=0; s<charbStr.length;s++)
if(s<charbStr.length-1)
if(charbStr[s]==':'&&charbStr[s+1]==':')
//System.out.println(" s0: " + s);
for(int ss=s+2;ss<s+12;ss++)
//System.out.println("ss: "+ ss + " s: " + s);
if(charbStr[ss]==':')
//System.out.println("in");
header[ctr] = bStr.substring(s,ss);
//System.out.println("1ss: " + ss + " s: " + s);
for(int c=ss+1;c<charbStr.length;c++)
if(charbStr[c]==':')
//System.out.println("ctr: " + ctr + " " +"entries[0]" + entries[0][0]+ "\n"+ entries[0][1] + "\n" + entries[1][0] + "\n" + entries[1][1]);
if(ss<charbStr.length)entries[ctr][e++] = bStr.substring(ss+1,c);
//System.out.println("c:" + c);
ss= c;
ctr++;
e=0;
//System.out.println("header: " + header);
//System.out.println("entires[0]0: " + entries[0][0]);
//System.out.println("entires[0]1: " + entries[0][1]);
//System.out.println("entires[1]0: " + entries[1][0]);
//System.out.println("entires[1]1: " + entries[1][1]);
//System.out.println("entires[2]0: " + entries[2][0]);
//System.out.println("entires[2]1: " + entries[2][1]);
String timeConnect[][] = new String[5][100];
char myChars[] = null;
for(int d=0;d<5;d++)
for(int f = 0;f<100-1;f++)
for(int cs=0;cs<entries[d][f].length();cs++)
if(!(entries[d][f].equals("")))
myChars = entries[d][f].toCharArray();
for(int a=0;a<entries[d][f].length();a++)
if(myChars[a]==';')
for(int k=a;k<entries[d][f].length();k++)
timeConnect[d][f]= entries[d][f].substring(a,k);
// System.out.println("time: " + timeConnect[d][f]);
//for(int o=0;o<5;o++)
//System.out.println("Header["+o+"]" + header[o]);
try {
PrintWriter output = new PrintWriter(socket.getOutputStream(), true);
BufferedReader input = new BufferedReader(
new InputStreamReader(
socket.getInputStream()));
String inLine, outLine;
outLine = getInput(null);
output.println(outLine);
while ((inLine = input.readLine()) != null) {
244: outLine = getInput(inLine);
output.println(outLine);
System.out.println(inLine);
outputStrings += inLine;
//if(inLine.equals("Hello."))break;
timeOfConnect[conCtr++]= " " Integer.toString(hour)":"+Integer.toString(min)+":"+Integer.toString(sec);
if(c.PM==1){System.out.println("HL");timeOfConnect[conCtr-1]+="PM";}
System.out.println(timeOfConnect[conCtr-1]);
outputStrings += "\n"+ timeOfConnect[conCtr-1];
//System.out.println("output");
try {
//FileWriter fw1 = new FileWriter("C:\\San Server Data\\Connectlog.txt");
bw1 = new BufferedWriter(new FileWriter("C:\\San Server Data\\Connectlog.txt",true));
//PrintWriter pw2 = new PrintWriter(bw1);
System.out.println(outputStrings);
//pw2.println(outputStrings);
if(next == 0)
bw1.write(outputStrings);
if(next == 1)
bw1.write(outputStrings+ " D");
bw1.newLine();
bw1.flush();
//pw2.close();
catch (IOException io) {
System.out.println("Oh oh, Got and IOException error!"+io);
finally{
if(bw1 != null) try{
bw1.close();
catch(IOException io)
output.close();
input.close();
socket.close();
if(next == 0)next = 1;
else if(next == 1)next = 0;
//WONCUS1 won = new WONCUS1();
//String m[] = new String[1];
//won.main(m);
//won.start();
} catch (IOException err) {
err.printStackTrace();
//Client.java
public class Client {
public static Socket Socket = null;
public static BufferedReader i = null;
public static PrintWriter o = null;
public static String packetString = "CUSCarissa_Calton25242526"; //product id
public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
public static String fromServer;
public static String fromUser;
public static void main(String[] args) throws IOException {
int ars=0;
if (args.length > 0)
ars = Integer.parseInt(args[0]);
try {
Socket = new Socket("localhost", 4444);
o = new PrintWriter(Socket.getOutputStream(), true);
i= new BufferedReader(new InputStreamReader(Socket.getInputStream()));
} catch (UnknownHostException err) {
System.err.println("Can not find Server!");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get initialisation files to be represented in true statement!");
System.exit(1);
while ((fromServer = i.readLine()) != null) {
//int hour = Integer.parseInt(fromServer);
//System.out.println("Server: " + fromServer);
System.out.println("Server: " + fromServer);
if (fromServer.equals("Bye."))
break;
if (fromServer.equals("Hello."))
break;
fromUser = packetString;
if (fromUser != null) {
System.out.println("Client: " + fromUser);
//o.println(fromUser);
String getComp = InetAddress.getLocalHost().getHostName();
String ip = InetAddress.getLocalHost().getHostAddress();
o.println(fromUser+";"+getComp + " " + ip);
//o.println(getComp + " " + ip);"onclose event of application", at least do something such as call wait() on ReadersWhy? Who is going to notify() it?
and close the Sockets and then Readers/WritersI won't even ask why about that because it is 100% dead wrong. Close the outermost Writer or OutputStream. That flushes the output, closes the socket, and closes any input streams or readers. Taking your advice the flush() cannot occur. But the evidence is that he is closing the socket: in fact the operating system does that anyway. Possibly he needs to take the advice about closing the Writer/OutputStream, to cause the flush(), which might stop the server from writing. But that depends on the application. If it's legal in the application protocol for the client to exit while the server is still writing he will just have to put up with the 'connection resets', or at least interpret them properly rather than just logging them as an error.
If your using a window(GUI) you can use the main frame with a Window closing event.And that's completely irrelevant because the error happens on the server. -
Increasing socket muxer threads
Hello,
Had production performance issue today that was resolved by creating an execute queue with 200 threads and placing the offending servlet on that queue.
However, I noticed that the socket muxer with 3 threads is constantly busy. Is there any way to increase the number of threads for the muxer, or is this not a concern? Is it different if we are using native socket muxer? Have read several docs but still have no clear answer if we should be concerned about socket muxer.
Thanks,
RichThanks,
I'm familiar with that parameter. However, from some docs I got the, probably confused, impression that those are non-native (java?) threads, and that the socket readers parameter didn't have much to do with anything once you started using the native-io performance pack.
Thanks again,
Rich -
Need an example of server / client program with swing interface
Hi!
After a lot of trying i still haven't managed to create a server client program using swing components ...
can someone write a mini application to demonstrate how this can be done?
i would like to have a frame with a button a texField for input and a textAread for the output
What i have in mind is the following ..
say im the server
i write something in the textField and then i press the button
then the information written in the textFiled is passed to the client who shows it in his textArea
The same thing goes on with the client (he can write something in his own textField and when he presses the button the info is passed at the
server who puts it in his textArea) and vice versa.
i have written many classes that trying unsuccessfully to do that ... below i show my last attempt ...
I would appreciate if you could write a small application which it could to this.
The whole idea is to create a turn based game ( i have implemented the game engine and graphics and i try to add the internet function)
Here is the code ...( i would appreciate if you write a new code instead of trying to correct mine ( which i think it's impossible) in order to use it as a general example)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
@SuppressWarnings("serial")
* In order to have a more gereral program instead of passing strings between the server
* and the client a pass an MyObjext object. The MyObject class has an integer and a String
* (which is always the same) field . At the textField i write an integer number and i
* make a new MyObject which i want to pass to the server or the client and vice versa.
* The textArea shows the integer value of the MyObject which was passed from the server /client
public class MyUserInterface extends JFrame {
MyObject returnObject;
JTextField myTextField;
JTextArea te ;
ClientGame cg;
ServerGame sg;
* used to determine if the current instance is running as a client or host
boolean isHost;
//The constructor of the client
public MyUserInterface(ClientGame cg){
this("Client");
this.cg = cg;
isHost = false;
//The constructor of the server
public MyUserInterface(ServerGame sg){
this("Server");
this.sg = sg;
isHost = true;
//The general constructor used both by client and server ..
// it initializes the GUi components and add an actionListenr to the button
public MyUserInterface(String str) {
super(str);
myTextField = new JTextField(2);
te = new JTextArea();
te.setPreferredSize(new Dimension(100,100));
JButton okButton = new JButton("Ok");
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try{
int a = Integer.parseInt(MyUserInterface.this.myTextField.getText());
System.out.println(a); //used to control the flow of the program
MyUserInterface.this.returnObject = new MyObject(a);
//sends the data
sendData();
//waiting for response...
getData();
catch(Exception ex){System.out.println("Error in the UI action command" +
ex.printStackTrace();}
JPanel panel = new JPanel(new FlowLayout());
panel.add(okButton);
panel.add(myTextField);
panel.add(te);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().add(panel);
pack();
setVisible(true);
protected MyObject getReturnObject() {
return returnObject;
public void sendData(){
new Thread(new Runnable() {
@Override
public void run() {
if (!isHost)cg.sentData(returnObject); //using the Servers out and in methods
else sg.sentData(returnObject); //using the Clients out and in methods
System.out.println("data sending");
public MyObject getData(){
MyObject obj;
System.out.println("Retrieveing Data");
if (!isHost)obj = (MyObject)cg.getData();
else obj = (MyObject)sg.getData();
System.out.println(" data retrieved = "+ obj.getInt()); //just to control how the code flows
te.setText(obj.getInt()+"");
return obj;
public static void main(String[] args) {
*Initiating the Server
new Thread(new Runnable() {
@Override
public void run() {
ServerGame sg = new ServerGame();
new MyUserInterface(sg);
}).start();
* Initiating the Client
new Thread(new Runnable() {
@Override
public void run() {
ClientGame cg = new ClientGame("192.168.178.21"); //<----in case you run my code
//..don't forget to change to your
new MyUserInterface(cg); //ip
}).start();
import java.io.*;
import java.net.*;
public class ClientGame {
String ipAddress;
Socket clientSocket = null;
ObjectOutputStream out = null;
ObjectInputStream in = null;
public ClientGame(String ipAddress) {
this.ipAddress = ipAddress;
try {
System.out.println("Connecting To Host");
clientSocket = new Socket(InetAddress.getByName(ipAddress),4444);
System.out.println("Host Found ...Io initializaton");
out = new ObjectOutputStream(clientSocket.getOutputStream());
in = new ObjectInputStream(clientSocket.getInputStream());
} catch (UnknownHostException e) {
System.err.println("Don't know about host: taranis.");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for the connection to: taranis.");
System.exit(1);
public Object getData(){
Object fromServer = null ;
do{
try {
fromServer = in.readObject();
catch(ClassNotFoundException ex){}
catch(IOException e){}
}while(fromServer==null);
return fromServer;
public void sentData(final Object obj){
new Thread(new Runnable() {
@Override
public void run() {
try{
out.writeObject(obj);
catch(IOException e){}
}).start();
public void terminateConnection(){
try{
out.close();
in.close();
clientSocket.close();
catch (IOException e){}
public class ServerGame {
ServerSocket serverSocket;
Socket clientSocket;
ObjectOutputStream out = null;
ObjectInputStream in = null;
public ServerGame() {
try{
serverSocket = new ServerSocket(4444);
clientSocket = serverSocket.accept();
out = new ObjectOutputStream(clientSocket.getOutputStream());
in = new ObjectInputStream(clientSocket.getInputStream());
catch(IOException e){System.out.println("IOException in ServerGame");}
public Object getData(){
Object fromClient = null ;
do{
try {
fromClient = in.readObject();
catch(ClassNotFoundException ex){}
catch(IOException e){}
}while(fromClient==null);
return fromClient;
public void sentData(final Object obj){
new Thread(new Runnable() {
@Override
public void run() {
try{
out.writeObject(obj);
catch(IOException e){}
}).start();
public void terminateConnection(){
try{
out.close();
in.close();
clientSocket.close();
serverSocket.close();
catch (IOException e){}
public static void main(String[] args) {
new ServerGame();
import java.io.Serializable;
* this is a test object
* it has a String field and a value
* The string is always the same but the integer value is defined in the constructor
public class MyObject implements Serializable{
private static final long serialVersionUID = 1L;
String str;
int myInt;
MyObject(int a){
str = "A String";
myInt = a;
public int getInt(){
return myInt;
}Pitelk wrote:
I believe that a good code example can teach you things ;that you would need many days of searching; in no timeSo lets write one small example.. Ill help a little, but you do most of the work.
jverd approach is deffenetly the way to go.
jverd wrote:
* Write a very small, simple Swing program with an input area, an output area, and a button. When you click the button, what's in the input area gets copied over to the output area.This part is partially done.
* Write a very small, simple client/server program without Swing. It should just send a couple of hardcoded messages back and forth.And this part is for you(Pitelk) to continue on. I cannot say that this is the best way. or that its good in any way. I do however like to write my client/server programs like this. And perhaps, and hopefully, Ill learn something new from this as well.
This is how far I got in about 10-20min..
package client;
* To be added;
* A connect method. That connects the client to the server and
* opens up both the receive and transmit streams. After doing that
* the an instance of the ServerListener class should be made.
* Also an disconnect method could be usable. But thats a later part.
public class TestClass1 {
package utils;
import java.io.ObjectInputStream;
import client.TestClass1;
* This class is meant to be listening to all responses given from
* the server to the client. After a have received data from the
* server. It should be forwarded to the client, in this case
* TestClass1.
public class ServerListener implements Runnable {
public ServerListener(ObjectInputStream in, TestClass1 tc) {
@Override
public void run() {
while(true) {
package server;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
* This class should handle all data sent to the server from the clients.
class Server implements Runnable {
private static List<ObjectOutputStream> outStreams = new ArrayList<ObjectOutputStream>();
private Socket client = null;
public Server(Socket client) {
this.client = client;
@Override
public void run() {
while(true) {
* The meaning of this class is to listen for clients trying to connect
* to the server. Once connection is achieved a new thread for that client
* should be made to listen for data sent by the client to the server.
public class ChatServer implements Runnable {
@Override
public void run() {
while(true) {
package utils;
import java.io.Serializable;
@SuppressWarnings("serial")
public class MyObject implements Serializable {
private String mssg;
private String clientID;
private String clientName;
public MyObject(String mssg, String clientID, String clientName) {
this.mssg = mssg;
this.clientID = clientID;
this.clientName = clientName;
//Generate getters and setters..
}Continue on this, and when you get into problems etc post them. Also show with a small regular basis how far you have gotten with each class or it might be seen as you have lost intresst and then this thread is dead.
EDIT: I should probably also say that Im not more than a java novice, at the verry most. So I cannot guarantee that I alone will be able to solve all the problems that might occure during this. But Im gonna try and help with the future problems that may(most likely will) occure atleast(Trying to reserve my self incase of misserable failiure from me in this attempt).
Edited by: prigas on Jul 7, 2008 1:47 AM -
My first Server/Client Program .... in advise/help
Hello,
I am learning about Sockets and ServerSockets and how I can use the. I am trying to make the simplest server/client program possible just for my understanding before I go deper into it. I have written two programs. theserver.java and theclient.java the sere code looks like this....
import java.net.*;
import java.io.*;
import java.util.*;
public class theserver
public static void main(String[] args)
{ // IOReader r = new IOReader();
int prt = 3333;
BufferedReader in;
PrintWriter out;
ServerSocket serverSocket;
Socket clientSocket = null;
try{
serverSocket = new ServerSocket(prt); // creates the socket looking on prt (3333)
System.out.println("The Server is now running...");
while(true)
clientSocket = serverSocket.accept(); // accepts the connenction
clientSocket.getKeepAlive(); // keeps the connection alive
out = new PrintWriter(clientSocket.getOutputStream(),true);
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
if(in.ready())
System.out.println(in.readLine()); // print it
catch (IOException e) {
System.out.println("Accept failed:"+prt);
and the client looks like this
import java.net.*;
import java.io.*;
public class theclient
public static void main(String[] args)
BufferedReader in;
PrintWriter out;
IOReader r = new IOReader();
PrintWriter sender;
Socket sock;
try{
sock = new Socket("linuxcomp",3333); // creates a new connection with the server.
sock.setKeepAlive(true); // keeps the connection alive
System.out.println("Socket is connected"); // confirms socket is connected.
System.out.println("Please enter a String");
String bob = r.readS();
out = new PrintWriter(sock.getOutputStream(),true);
out.print(bob); // write bob to the server
catch(IOException e)
System.out.println("The socket is now disconnected..");
If you notice in the code I use a class I made called IOReader. All that class is, is a buffered reader for my System.in. (just makes it easier for me)
Ok now for my question:
When I run this program I run the server first then the client. I type "hello" into my system.in but on my server side, it prints "null" I can't figure out what I am doing wrong, if I am not converting correctly, or if the message is not ever being sent. I tried putting a while(in.read()) { System.out.println("whatever") } it never reaches a point where in.ready() == true. Kinda of agrivating. Because I am very new to sockets, I wanna aks if there is somthing wrong with my code, or if I am going about this process completely wrong. Thank you to how ever helps me,
Cobbwebhere's my simple server/client Socket :
Server:
import java.net.*;
import java.io.*;
public class server
public static void main(String a[])
ServerSocket server=null;
Socket socket=null;
DataInputStream input=null;
PrintStream output=null;
try
server=new ServerSocket(2000);
socket=server.accept();
input = new DataInputStream(socket.getInputStream());
output = new PrintStream(socket.getOutputStream());
//output.println("From Server: hello there!");
String msg="";
while((msg=input.readLine()) != null)
System.out.println("From Client: "+msg);
catch(IOException e)
catch(Exception e)
}Client:
import java.net.*;
import java.io.*;
public class client
static private Socket socket;
static private DataInputStream input;
static private PrintStream output;
public static void main(String a[])
try
socket=new Socket("10.243.21.101",2000);
System.out.println("\nconnected to: \""+socket.getInetAddress()+"\"");
input=new DataInputStream(socket.getInputStream());
output=new PrintStream(socket.getOutputStream());
output.println("From Client(Tux): "+a[0]);
String msg="";
//while((msg=input.readLine()) != null)
System.out.println("From Server(Bill): "+msg);
catch(java.io.IOException e)
catch(Exception e)
} -
Help with my FTP client program
Hello All,
I am trying to modify a client FTP program to get a grasp on network programming. However when I try to connect to the host I get an error of Anonyymous login. What am I doing wrong? Below is the FTPclass program that I found on the net. How do resolve this issue? Thanks!!
* Connects to the given FTP host on port 21, the default FTP port.
// public boolean connect(String host, int port, String userName, String passWord) throws UnknownHostException,
// IOException {
// return connect(host, 21, userName, passWord);
* Connects to the given FTP host on the given port.
public boolean connect(String host, int port, String userName, String passWord) throws UnknownHostException,
IOException {
connectionSocket = new Socket(host, port);
outputStream = new PrintStream(connectionSocket.getOutputStream());
inputStream = new BufferedReader(new InputStreamReader(connectionSocket
.getInputStream()));
if (!isPositiveCompleteResponse(getServerReply())) {
disconnect();
return false;
return true;
* Disconnects from the host to which we are currently connected.
public void disconnect() {
if (outputStream != null) {
try {
if (loggedIn) {
logout();
outputStream.close();
inputStream.close();
connectionSocket.close();
} catch (IOException e) {
outputStream = null;
inputStream = null;
connectionSocket = null;
* Wrapper for the commands <code>user [username]</code> and <code>pass
* [password]</code>.
public boolean login(String username, String password) throws IOException {
int response = executeCommand("user " + username);
if (!isPositiveIntermediateResponse(response))
return false;
response = executeCommand("pass " + password);
loggedIn = isPositiveCompleteResponse(response);
return loggedIn;
* Added by Julian: Logout before you disconnect (this is good form).
public boolean logout() throws IOException {
int response = executeCommand("quit");
loggedIn = !isPositiveCompleteResponse(response);
return !loggedIn;
* Wrapper for the command <code>cwd [directory]</code>.
public boolean changeDirectory(String directory) throws IOException {
int response = executeCommand("cwd " + directory);
return isPositiveCompleteResponse(response);
* Wrapper for the commands <code>rnfr [oldName]</code> and <code>rnto
* [newName]</code>.
public boolean renameFile(String oldName, String newName)
throws IOException {
int response = executeCommand("rnfr " + oldName);
if (!isPositiveIntermediateResponse(response))
return false;
response = executeCommand("rnto " + newName);
return isPositiveCompleteResponse(response);
/**Here is the code to test the client program
lass verifyFTP {
public static void main(String[] args) {
String serverName;
String portNumber;
int port = 21;
FTPConnection ftp = null;
try {
if (args.length == 0) {
serverName = getStringFromUser("Enter the server you would like to connect to: ");
if (serverName.length() == 0) {
return;
}//end if
} else {
serverName = args[0];
}//end else
String userName = "";
String passWord = "";
// set the FTPConnection parameter to true if you want to
// see debug output in your console window
ftp = new FTPConnection(true);
System.out.println("Attempting to connect to " + serverName);
ftp.connect(serverName, port, userName, passWord);
if(ftp.login("", "")){
System.out.println("Successfully logged in!");
System.out.println("System type is: " + ftp.getSystemType());
System.out.println("Current directory is: "
+ ftp.getCurrentDirectory());
String files = ftp.listFiles();
// private function that gets console input from the user
private static String getStringFromUser(String prompt) throws IOException {
System.out.print(prompt);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
return br.readLine();You should print out exactly what you are sending and what you are recieving via the socket. You do this just before you send it and when you receive it (you do not modify it in any way first.)
You should also use an existing FTP client to log into your server. Presumably it is successful. Then you can use ethereal (free software google it) to examine exactly what the FTP client sends versus what you are sending. You will probably find that it is sending a different command than what you are. -
How can connect different ejb server in one client program
hi , every
i want to make connect ejb server into one client program.
for that , but i try to change PROVIDER_URL property , it's not correct
who solve this problem for novice? :(You need to create separate initialContext to each of the different servers
and lookup up the different ejbs.
-Sabha
"inking" <[email protected]> wrote in message
news:[email protected]..
hi , every
i want to make connect ejb server into one client program.
for that , but i try to change PROVIDER_URL property , it's not correct
who solve this problem for novice? :( -
How to run the client program in weblogic 8.1 server
Hi
I am new to EJB 2.0. I am deployed sucessfully a session ejb program.
While running an ejb client program it throws an exception. In my session ejb program i created two jar file. one is sessionejb.jar and another one is sessionejbclient.jar. In sessionejb.jar contains home ,remote ,session bean class and deployment descriptor.In sessionejbclient.jar contains home,remote and client program. Both jar files are included in class path of environment variable( i am using Standalone server).
Plese guide me how to run an session ejb client correctly.
Regards
JaiganeshBoth jar files are
included in class path of environment variable( i am
using Standalone server).did u include both these jars in the "weblogic's class path" ?
in that case, it obviously wont work.
what u need is an understanding of the following topics (i have described them briefly, but for details u can always check the documentation of weblogic):
1. Class loaders in weblogic: there are various levels of class loaders. at the top is the weblogic's class loader. below it are various EARs' class-loaders. and so on....
2. Packaging. You must ensure that in the same class loader, there are not two classes from 2 different jars.
hope that helps
Maybe you are looking for
-
Depreciation in Asset Accounting
Hi Gurus, Total Acquisition Value is 120000 Depreciation already deducted for 9 months, 10000 each month. For remaining 30000, i have to deduct the whole amount in 10th month. It means i want to deduct 30000 depreciation in 10th month. Can you sugges
-
Login error in OIM 11.1.1.5
Hi, I am getting the below error when trying to login on OIM application. Earlier it was working fine. Message: Automation server can't create object Line: 5689 Char: 2 Code: 0 URI: http://HostName:14000/oim/afr/partition/ie/default/opt/boot-11.1.1.5
-
I have an iPhone 3GS and recently upgraded to iOS4. Yesterday I downloaded the latest upgrade to the OS (the one with the signal strength fix) and now my phone cannot find my network. I am in the UK and subscribe to the Orange UK network. Does anyone
-
Hi, I made movies in HD standard (1440 x 1080i) comprising HD material (1280 x 720) and stills (1920 x 1080) and included slide shows (jpg´s 1920 x 1080 px, 180 dpi). The movies and slide shows look fine on the screen (crisp & sharp). After including
-
I've read the other threads on TM slowness, etc. but need some interpretation of what this Console entry means (see below.) As you can see, TM was doing fine and has been for several months until today. Then it suddenly stopped doing the hourly backu