I have a question about socket
I've got a socket question that haven't to work out for two days . If you know something about this question please give me a hand , Thank you .............
===================================================
I want to write a program about PortMapping with Java.
It means : put one port's data to another port .
=============================
Just like :
There is a Tomcat Web Server listener on the 8080 port, and I want to make a socket that listener on the 9090 port. When the client use the Browse visit my web on 9090 port , this socket will be send this data stream from 9090 port to 8080 port and then the Tomcat Web Server process this data and return the result to client use the 9090 port .
=============================
(In order to let this program suit for every model (include c/s and b/s),so I think it must be use the byte[] stream )
====================================================
BinaryPort.java
package sailing;
import java.io.*;
import java.net.*;
public class BinaryPort implements Runnable
private ServerSocket listenerSocket;
private Socket serverSocket;
private Socket tomcatSocket;
private Thread myThread;
private DataInputStream in;
private DataOutputStream out;
private ByteArrayOutputStream swapStream;
public BinaryPort()
try
System.out.println("Server is starting ..................");
this.listenerSocket=new ServerSocket(9090);
this.tomcatSocket=new Socket("127.0.0.1",8080);
this.swapStream=new ByteArrayOutputStream();
this.myThread=new Thread(this);
this.myThread.start();
catch(Exception e)
System.out.println(e);
public void run()
while(true)
try
this.serverSocket=this.listenerSocket.accept();
this.in=new DataInputStream(this.serverSocket.getInputStream());
byte[] buf=new byte[100];
int rc=0;
while((rc=in.read(buf,0,buf.length))>0)
this.swapStream.write(buf,0,rc);
this.swapStream.flush();
byte[] resBuf=swapStream.toByteArray();
this.out=new DataOutputStream(this.tomcatSocket.getOutputStream());
this.out.write(resBuf,0,resBuf.length);
this.out.flush();
//Get The Tomcat Web Server reBack Information
this.in=new DataInputStream(this.tomcatSocket.getInputStream());
byte[] buf2=new byte[100];
int rc2=0;
this.swapStream=null;
while((rc2=in.read(buf2,0,buf2.length))>0)
this.swapStream.write(buf2,0,rc2);
this.swapStream.flush();
rc2=0;
byte[] resBuf2=swapStream.toByteArray();
this.out=new DataOutputStream(this.serverSocket.getOutputStream());
this.out.write(resBuf2,0,resBuf2.length);
this.out.flush();
this.myThread.sleep(1000);
this.out.close();
this.in.close();
catch(Exception e)
System.out.println(e);
public static void main(String args[])
new BinaryPort();
====================================================
I found that it stop on the first "while" , and I don't know what is the reason .............
Well , I've got it ~~~~~~~~~
if the read method hasn't the another data , this method will be stoped . so ..............
===============================
package sailing;
import java.io.*;
import java.net.*;
public class ModifyBinaryPort
private ServerSocket listenerSocket;
private Socket serverSocket;
public ModifyBinaryPort()
try
System.out.println("Server is starting ..................");
this.listenerSocket=new ServerSocket(9633);
while(true)
try
this.serverSocket=this.listenerSocket.accept();
new MyThread(serverSocket).start();
catch(Exception e)
System.out.println(e);
catch(Exception e)
System.out.println(e);
public static void main(String args[])
new ModifyBinaryPort();
class MyThread extends Thread
private Socket threadSocket;
private Socket tomcatSocket;
private Thread myThread;
private DataInputStream in;
private DataOutputStream out;
public MyThread(Socket socket)
try
threadSocket=socket;
this.tomcatSocket=new Socket("127.0.0.1",9090);
catch(Exception e)
System.out.println(e);
public void run()
try
//Read Thread
new ReadClientWriteTomcatThread(threadSocket,tomcatSocket).start();
catch(Exception e)
System.out.println(e);
class ReadClientWriteTomcatThread extends Thread
private DataInputStream read;
private DataOutputStream write;
private ByteArrayOutputStream swapStream;
private Socket threadSocket;
private Socket tomcatSocket;
public ReadClientWriteTomcatThread(Socket threadSocketT,Socket tomcatSocketT)
try
threadSocket=threadSocketT;
tomcatSocket=tomcatSocketT;
read=new DataInputStream(threadSocket.getInputStream());
write=new DataOutputStream(tomcatSocket.getOutputStream());
this.swapStream=new ByteArrayOutputStream();
catch(Exception e)
System.out.println(e);
public void run()
try
byte[] buf=new byte[100];
int rc=0;
while((rc=read.read(buf,0,buf.length))>0)
this.swapStream.write(buf,0,rc);
this.swapStream.flush();
if(rc<buf.length)
break;
//System.out.println(rc);
byte[] resBuf=swapStream.toByteArray();
this.write.write(resBuf,0,resBuf.length);
this.write.flush();
//Reading the result from tomcat
new ReadTomcatWriteClientThread(threadSocket,tomcatSocket).start();
catch(Exception e)
System.out.println(e);
class ReadTomcatWriteClientThread extends Thread
private DataInputStream read;
private DataOutputStream write;
private ByteArrayOutputStream swapStream;
public ReadTomcatWriteClientThread(Socket threadSocket,Socket tomcatSocket)
try
read=new DataInputStream(tomcatSocket.getInputStream());
write=new DataOutputStream(threadSocket.getOutputStream());
this.swapStream=new ByteArrayOutputStream();
catch(Exception e)
System.out.println(e);
public void run()
try
byte[] buf2=new byte[100];
int rc2=0;
while((rc2=read.read(buf2,0,buf2.length))>0)
this.swapStream.write(buf2,0,rc2);
this.swapStream.flush();
if(rc2<buf2.length)
break;
byte[] resBuf2=swapStream.toByteArray();
this.write=new DataOutputStream(write);
this.write.write(resBuf2,0,resBuf2.length);
this.write.flush();
this.write.close();
this.read.close();
catch(Exception e)
System.out.println(e);
}==================
but it still has some little bug , I think I will work out soon .........
Thanks for your help ejp .............
Similar Messages
-
I hava a question about RMI,please help me!
Ladys and Gentleman,I hava a question about RMI.I wirte four little programs in java that is about RMI on my PC.
import java.rmi.*;
public interface AddServerIntf extends Remote{
double add(double d1,double d2) throws RemoteException;
import java.rmi.*;
import java.rmi.server.*;
public class AddServerImpl extends UnicastRemoteObject implements AddServerIntf{
public AddServerImpl() throws RemoteException{
public double add(double d1,double d2)throws RemoteException{
return d1+d2;
import java.net.*;
import java.rmi.*;
public class AddServer{
public static void main(String args[]){
try{
AddServerImpl addServerImpl=new AddServerImpl();
Naming.rebind("AddServer",addServerImpl);
}catch(Exception e){
e.printStackTrace();
import java.rmi.*;
public class AddClient
public static void main(String args[]){
try{
String addServerURL="rmi://"+args[0]+"/AddServer";
AddServerIntf addServerIntf=(AddServerIntf) Naming.lookup(addServerURL);
System.out.println("The first number is: "+args[1]);
double d1=Double.valueOf(args[1]).doubleValue();
System.out.println("The second number is: "+args[2]);
double d2=Double.valueOf(args[2]).doubleValue();
System.out.print("The sum is: "+addServerIntf.add(d1,d2));
}catch(Exception e){
System.out.println("Exception: "+e);
And I compiled these files,so I got 4 class files(AddServer.class,AddServerIntf.class,AddServerImpl.class,AddServerClient.class).Then I use "rmic AddServerImpl" got another two files(AddServerImpl_Skel.class and AddServerImpl_Stub.class).Then I input command:rmiregistry,in another window,I input command:java AddServer,I got some exceptions,I was confused by these exceptions.The exception is:
D:\MyJava\rmi_3>java AddServer
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: AddServerImpl_Stub
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: AddServerImpl_Stub
java.lang.ClassNotFoundException: AddServerImpl_Stub
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Unknown Source)
at AddServer.main(AddServer.java:8)
But some times this exception will not appeared.Who can give me answer or suggestion,thanks a lot.
By the way,when I run shutdown.bat in tomcat_root\bin,I can get some exceptions:
C:\Tomcat\bin>shutdown
Using CATALINA_BASE: ..
Using CATALINA_HOME: ..
Using CATALINA_TMPDIR: ..\temp
Using JAVA_HOME: C:\JDK
Catalina.stop: java.net.ConnectException: Connection refused: connect
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:350)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:137)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:124)
at java.net.Socket.<init>(Socket.java:268)
at java.net.Socket.<init>(Socket.java:95)
at org.apache.catalina.startup.Catalina.stop(Catalina.java:579)
at org.apache.catalina.startup.Catalina.execute(Catalina.java:402)
at org.apache.catalina.startup.Catalina.process(Catalina.java:180)
at java.lang.reflect.Method.invoke(Native Method)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:203)
I use Windows server 2000+JDK 1.3.1_04+tomcat 4.1.7Maybe I am off base here but it seems to me the problem is the way in which you bind your server. The server must be bound to the same address and you are looking up from, i.e. "rmi://" host "/AddServer"
so
Naming.rebind("AddServer",addServerImpl);should be
Naming.rebind("rmi://127.0.0.1/AddServer", addServerImpl);to match
String addServerURL="rmi://"+args[0]+"/AddServer";
AddServerIntf addServerIntf=(AddServerIntf)
Naming.lookup(addServerURL);Hopefully this will solve your problem, if not it is a problem with your classpath. An easy way to make sure it can see your files is to set the java.rmi.server.codebase to point to where your classes are, e.g.
java -Djava.rmi.server.codebase=file:"c:\\cygwin\\home\\tweak\\keck_folder\\cmsi401\\RMIGalaxySleuth\\classes\\" AddServer
I had to set the codebas for my rmi stuff to work no matter how much I messed with the classpath.
Hope this helps,
Will -
I have a question about Lightroom 5... I used it last night, I go to get on it today and its will not open. I have an error msg "Lightroom encountered an error when reading from its preview cache and needs to quit" Lightroom will attempt to fix the problem when reopened
https://forums.adobe.com/message/6219922#6219922
See if the issue in the thread above helps you to solve your problem. -
Hi I have a question about shooting in Raw with my Canon EOS 6d.
I'm in the process of learning photography and my goal was to start shooting in raw.
I have Photoshop CS5. When I tried to edit my images in raw I received an error message stating, "The photoshop camera raw plug-in did not recognize the format. If these files are from a camera, you may need to update your camera raw plug in."
In researching the issue I read that to edit in raw you need a camera model requirement of at least 7.3 which only works with CS6. My version of CS5 is 6.0.0.205. Being new to all this I see that my options are to upgrade to CS6 or convert by using DNG converter and paying a monthly fee. Two things I know nothing about and don't know which is would be more beneficial.
I'd appreciate any advise on which route to go and how upgrade and what it may cost. THANKS in advance!
HeatherIn researching the issue I read that to edit in raw you need a camera model requirement of at least 7.3 which only works with CS6.
That is correct. Your camera was first supported by Camera Raw 7.3. Camera Raw 7.3 will not work with CS5. You need CS6 or CC.
Being new to all this I see that my options are to upgrade to CS6 or convert by using DNG converter and paying a monthly fee. Two things I know nothing about and don't know which is would be more beneficial.
I'd appreciate any advise on which route to go and how upgrade and what it may cost.
It all depends on your preferred workflow and your budget.
Using the DNG converter is free. There is no monthly fee. You use the converter to convert all Raw files from the EOS 6D to DNGs then edit the DNGs in CS5. That's an extra step every time - every photo. Some people don't like the extra step. Others don't mind.
Camera raw, DNG | Adobe Photoshop CC
Or you can upgrade to CS6 (non-Cloud) and pay the upgrade fee
Creative Suite 6
Or join the Cloud and pay the monthly fee
Or join the Photoshop Photography Program (US9.99/month) and get PS CC+LR -
Hi, I have a question about iCloud. I have an ipod 4th generation and im getting a 5th generation. i have lots of games such as subway surfers and temple run 2. I worked and played really hard on earning stuff and have also made in app purchases. Does iCloud save that kind of stuff?
See:
iOS: Transferring information from your current iPhone, iPad, or iPod touch to a new device
However, not all in-app purchases will transfer to another device. For which ones ill not see:
iTunes Store: About In-App Purchases -
Hello ! i have a question about my Hard's Disc storage space. I have Mac book Pro 11" Retina with hard disk 120 GB . I want to make this update but its impossible because of no free space. And now i want to ask. Its 120 GB full space but i dont know how. It tells me lets say i have 30 GB movies but i dont have anything ! Can you help me with any way ? If i can do something to see what movies let's say means !
Thank you !!Hope this helps.
1. Empty Trash.
http://support.apple.com/kb/PH10677
2. Start up in Safe Mode
http://support.apple.com/kb/PH11212
3. Delete "Recovered Messages", if any.
Hold the option key down and click "Go" menu in the Finder menu bar.
Select "Library" from the dropdown.
Library > Mail > V2 > Mailboxes
Delete "Recovered Messages", if any.
Empty Trash. Restart.
4. Repair Disk
Steps 1 through 7
http://support.apple.com/kb/PH5836
5. Disk space / Time Machine ?/ Local Snapshots
http://support.apple.com/kb/ht4878
6. Re-index Macintosh HD
System Preferences > Spotlight > Privacy
http://support.apple.com/kb/ht2409
If this does not help, you have to buy an external HD and move your movies photos.etc to
the external HD. -
I have a question about extracting pages. When I do the function, adobe saves the individual files as "<file name><space><page number>", so the files look like this "filename 1.pdf", "filename 2.pdf", "filename 3.pdf". Without too many gory details, I am using excel to concatenate some data to dynamically build a hyperlink to these extraced files. It casues me problems, however, for the space to be the the file name. Is there any way to change the default behavoir of this function to perhaps use a dash or underscore instead of a space?
No, you can't change the default naming scheme. You can do it yourself if you extract the pages using a script instead of using the built-in command.
-
I have a question about DWG files. What app will allow me to open DWG files to view them on my Macbook Pro?
Perform this Google search: ".dwg files on mac." The results should provide answers for you.
-
I have a question about Configuration of Post with Clearing
I have a question about confiruation of the post with clearing which is t-doce 'FB05'.
When I make post with clearing on 'FB05', I can change the additional selections.
Where can I control the confiruation of the additional selections in t-code 'FB05'
Please, tell me the menu path.Hi,
In SPRO, go to
Financial Accounting (New) > Accounts Receivable and Accounts Payable > Business Transactions > Incoming Payments > Manual Incoming Payments > Make Settings for Processing Open Items > Choose Selection Fields
Hope this helps.
Thanks -
I have a question about using multiple ipads in our school. Each of our teachers have a iPad and AppleTV in their classroom. The issue is, with our classrooms so close in proximity to one another, is there a way to pair teacher #1 iPad to its AppleTV without effecting/projecting onto the adjacent teachers #2 classroom AppleTV?
Not as such.
Give the AppleTV units unique names and also enable Airplay password in settings with unique passwords for each teacher.
AC -
Make sure that your bean is implementing the serializable interface and that
you are accessing the bean from the session with the same name.
Bryan
"Sandeep Suri" <[email protected]> wrote in message
news:[email protected]..
Hi, I have quick question about use of USEBEAN tag in SP2. When I
specify a scope of SESSION for the java bean, it does not keep the
values that I set for variable in the bean persistent.Thanks,Sonny
Try our New Web Based Forum at http://softwareforum.sun.com
Includes Access to our Product Knowledge Base! -
Please i have a question about to YOUTUBE App.
Dear all,
i have a question about YOUTUBE app.
i have Iphone 3G.
as i use youtube a new error message has appeared "Cannot Connect to YouTube"
noted that i could't use YouTube before.
Thanks ,
AshrafI don't use that app. I just go to the web based site. You can share videos from the site, but not from the app, as far as I have been able to do. Try the web based version and see if you get the same error. Go through Safari is what I mean.
-
I have a question about japan new depriciation engine using non-japanese chart of deprication
Hi, all
I have a question about link between new depriciation engine and chart of depriciation.
My client want to use US chart of depriciation as standard chart of depriciation becuase it has already standard setting like IAS deprication keys.
it means I have to create Japanese chart of depriciation by copying from US chart of depriciation(non-japanese sample(0JP))
I have a little doubt about it. In my previous project, I copyed chart of depriciation by copy from Japan sample Chart of depriciation(0JP) stored in SAP.
Is it possible to copy from non-japan sample charg of depriciation to using Japanese new depriciation engine? I worried some errors will occrues if I do not use sample chart of depriciation(0JP) .
If I need to use sample Japanese chart of depriciation, please give me the idea why I need to use Japanese sample chart of depriciation. I want to know the examples of non-Japanese asset accouting consultants who have working experience in the area.
Thank you.Hi, Narasimhulu
Thank you for your support.
My client use one COA to all over the world. And not only Japan, other country aslo use the COD which is copied from that of US. Basic reporting line is for USGAP. I will customize 2 depriciation ares, one for US GAP and another is JGAP. No need to create TAX realted customize. It means it enought only adding Japanese new depriciation keys to Current US COD. No need to add more Japanese local requirements.
In this case, I want to know follwoing point.
I know COD controll depriciation keys, but I want to know more detail about COD, what kinds of controls COD do. What is Japanese local requirements. Why better to use COPY of JP COD.
Thank you. -
I have a question about weblogic RMI , how can I resolve it.Thank you
I have a question about the weblogic RMI .
I have a program.web services+weblogic RMI +Data Sources When I run the program in the console application.it is ok.But When i run it with the web services(it 'is mean Get some parameter and run the different program).it's fail.The Exception is
cannot assign instance of yype weblogic.rmi.RMIServices_1033_WLStub to field demo.RMIServer_1033_WLStub.stubinfo of type weblogic.rmi.internal.StubInfo in instance of demo.RMIEsrver_1033_WLStub
how to resolve .Thank you.Hi Charles,
Parental Controls has always had problems with https sites, no idea if it's fixed in 10.9.x or not.
When you setup your Mac it shouldv'e made an admin account, are you not running from that account, or did you somehow change it to a Managed account??? -
I have a question about using adobe CS files in CS6 edition
I am a graphic artist . I have a question about using adobe CS files in CS6 edition. when I am gonna open thse adobe CS created files in CS6 Edition i get a color variation than i made with the CS version.Please give me an idea about this issue as soon as possible.If you need i can upload my problem as a screenshot to clearity
donrulz,
Are your Edit>Color Settings the same?
Are you using spot colours, such as Pantone (there have been some changes in CMYK values with new colour books)?
Maybe you are looking for
-
It originally did not download correctly. I refreshed the download and it supposedly completed. Upon playing the song in both my library and on the Itunes store it will not play past the first 5 seconds. How can I fix this?
-
Field Desc Not appearing in SE16 in NL language
Hi, My Problem is as follows I have a table with some fields. When I goto Se16 and display the data of the table the Column heading doesn't come for one field with Login Language NL. The field is attached to a data element and the data element has th
-
EDI Shipment Output Master Data Conversion
Hi, I am using LSMW to upload EDI Shipment Output Master Data into file can anyone suggest me any standard BAPI or Idoc avail for the same or any function module available to do this. Thanks Dhirendra
-
Please suggest me a datasource which contains these fields
Hai gurus, I am working for a roll out project where in sap is implemented for the client in one place and based on that we are making modification and building the same for the same client located in other places....so naturally there will be some g
-
I just bought a new Nikon D610 camera and I am shooting Camera Raw files. I am using PSCS5 with Camera Raw 6.5 plug in loaded. My question is I am unable to tranfer these files using my camera raw from my camera. I get no error message. My comuter ju