How can i reuse my existing socket connection
Hi,
this might sound basic, it probably is:
As part of my larger project, i have to send and recieve data to multiple socket connections.
The thing that happens is that everytime i send data, it seems that java is creating a new stream or something (code is multithreaded)
so as i send 4 items of data, a bit like a chat program sending 4 statements, it creates 4 different streams, instead of using the same stream. therefore when i close the connection, i get:
java.net.SocketException: Connection reset 4 times.
i know why.. its because i have added the:
Socket socket=new Socket(host, port);
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
bit in the same method with the
out.println(THE DATA....);
out.flush();
The thing what i want to do is to create the connection one, and reuse the objects:
out, in and socket
to send / recieve the new data.
please help me guys,
thanks
All the threads would be able to get the same reference to....
class SocketWrapper {
private final Object readLock = new Object();
private final Object writeLock = new Object();
// client side
public SocketWrapper(String hostname, int port);
// server side.
public SocketWrapper(Socket);
// send data
public void send(Serializable object) throws IOException;
// receive data. synchronized(writeLock);
public Serializable getNext() throws IOException;
// create a new socket as required, throw IllegalState if server side. synchronized(readLock)
private void createNewSocket() throws IllegalStateException;
}The send autoconnects as required. It then send on message/packet/object.
The getNext autoconnects as required. It reads one message/packet/object and returns.
This allows multiple threads to access the same socket. It allows data to be sent while a thread is blocking on a read. (Thus two locks)
Similar Messages
-
How can I reuse the BC4J database connection?
How can I reuse the BC4J database connection?
I want to use the application module connection without opening another in a custom code. At this level I canât access de ADF code, thatâs why I canât get the DBConnection from the application module.
Now, I have a âdata-sources.xmlâ in my project and the application module is configured to access the database from this xml file.I found the solution in other Forum. I worked ok.
Here the code:
If the Connections-Navigator connection is DBConnection1, the corresponding datasource is jdbc/DBConnection1DS.
1. Create a JSP page.
2. In the web.xml of the JSP add
<resource-ref>
<res-ref-name>jdbc/DBConnection1DS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
3. In the JSP page obtain a connection with the datasource.
InitialContext initialContext = new InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource)initialContext.lookup("java:comp/env/jdbc/DBConnection1DS");
java.sql.Connection conn = ds.getConnection(); -
I have been trying to get my computer (os x.7) to astablish a remote desktop connection to my work computer via a vpn tunnel. In fact I have just discovered that it works fine if i select to "send all traffic over vpn connection" from the options in the advanced setup of the vpn.
If the option is selected microsofts "Remote desktop connection for mac" works just fine. However without selecting the option it is not taking advantage of the tunnel but tries to connect as if the tunnel would not exist.
Now the question is how do I get program to use the vpn tunnel without checking the above option?
Thanks for any hints and pointers.Then can her computer be authorized to both accounts?
Absolutely. You can authorize any given computer to up to five iTunes Store accounts.
If purchases are made on her account, to a computer authorized to my account, can I put those songs on my iPod?
If you connect your iPod to her computer, yes. Tracks download only to the computer from which they're purchased, regardless of which iTunes Store account is used for the purchase. Or you could copy the tracks from her computer to yours and then authorize your computer to her iTunes Store account. But that's sort of defeating the original purpose, it would seem to me.
is it better to buy music through Amazon downloads and/or actually purchasing CDs to avoid the security features iTunes puts on its music?
That's certainly an option. If it's an entire album I want, I buy CDs. That way I can import them at the quality I want and to whichever of my systems I want. Amazon or one of the other download stores that offer tracks as MP3 are also an option, though for me download stores are best when you just want a couple of tracks off a given CD. -
Can Java make server side socket connections?
I plan on placing a java file (application or applet I don't know) on a website and have my application connect to the java file and tell it to connect to another host (outside of the website's domain) and send and receive data. Is this possible? If not why? If so, then should it be an applet or an application? Would I need to have it listen on a specific port or what?
I read this (http://java.sun.com/sfaq/):
"How can an applet open a network connection to a computer on the internet?
Applets are not allowed to open network connections to any computer, except for the host that provided the .class files. This is either the host where the html page came from, or the host specified in the codebase parameter in the applet tag, with codebase taking precendence.
For example, if you try to do this from an applet that did not originate from the machine foo.com, it will fail with a security exception:
Socket s = new Socket("foo.com", 80, true);"
- sun
And it through me for a loop.Think about this:
Any webpage may contain an applet.
Imagine the security implications if an applet could do whatever the developer wanted (erase your hard-drive, read your data, run your programs) without your permission.
Network connections are another example of the same thing.
Imagine you visit a webpage and an applet pops up that uses your computer to make a connection to government websites in an attempt to hack them.
Yikes.
So basically what happens (by default) is an applet starts of with a reduced set of permissions to protect the end user.
An application (by default) starts with more permissions you'd expect an application to have.
This is all configurable by the person who will be running the Applet or application. If someone trusts you, they can set up their runtime to give your applet all permissions, or give it a particular set of permissions. Or you can sign the applet with a digital signature, and if the end user trusts the certificate, and trusts you they can give your applet permissions that way.
Java Security, however, is not something that can be covered in one post on the forums.
You should probably look for some online tutorials/documentation or get a good book. -
How can i create a new usb connection (service) on my iMac for sharing internet from my iPhone5 ( i seem have to deleted it )
i know its not a problem whit my carrier o data plan or sharing preferences on the ipone because when i use it un my laptop it works perfectly through
the usb and even works on the Imac through wifi and bluethood tethering but NOT through usb!!.
the problem is that trying to make it work i deleted the "profile" usb iphone on the network prefereces panel. Now i only have 3 options: ethernet / wifi / bluetooth
but not the usb iPhone i used to have.
And when i try to add a new one i dont get a USB option.
can some one help me please??
this is how it looks (after the bluetooth PAN i used to have USB iPhone option)The question would be more appropriate in the Mac forums as it is not really related to the iPhone.
-
How can I checkout an existing file from CVS without going through the wiz
How can I checkout an existing file from CVS, that is not already in my local jdev, without going through the wizard and checkingout everything?
You can't. AI doesn't produce .PLT files.
-
HT5437 How can I use apple TV to connect my computer to the tv screen as an external monitor?
How can I use apple TV to connect my computer to the tv screen as an external monitor?
Morning jotref,
Thanks for using Apple Support Communities.
For more information on this, take a look at this article:
About AirPlay Mirroring in OS X Mountain Lion
http://support.apple.com/kb/ht5404
Best of luck,
Mario -
How can I get the ipad to connect to itunes 10.6.3?
How can I get the ipad to connect to itunes 10.6.3?
The iPad mini requires iTunes 10.7 or newer to sync.
(82182) -
How can I copy my existing contacts from 1 Apple ID to a new one?
How can I copy my existing contacts from 1 Apple ID to a new one?
Click here and pick the option which best fits your situation. Rented movies can only be moved through the iPod and will not play on the new computer if any other method is used.
(98456) -
How can I add an existing cfm page to a project?
CFB3 Question: How can I add an existing cfm page to a project? I created a project and copied a file into the project folder but I can't seem to find a way to add the cfm file into the project.
@Carl - Well heck, yes I did... But after reading your response I went back and tried right-clicking on and refreshing different things and what worked was right-clicking on the project name in the Navigator window and then clicking on refresh in that context menu.
Thank you Carl! -
How can i get my existing itunes account to recognizes a new ipod
How can I get my existing Itunes account to recognize a new ipod?
just plug it in. there would be on-screen instructions to help with the set up.
also consult the user guide that came with the device. -
I want to order a second copy of an existing iPhoto book. Though created in the smaller format now only the larger format is showing. How can I switch an existing iPhoto book back to the smaller format?
To change a book size duplicate it (select the book in the source pane and press command and D) since text flow and picture placements can change due to the size differences - then click on change themes, select the same theme and the new size
check it carefully
Before ordering your book preview it using this method - http://support.apple.com/kb/HT1040 - and save the resulting PDF for reference - the delivered book will match it.
LN -
How can I convert an existing table to IOT
Hi,
My Oracle version is 10.2.0.4
Below is my structure of my test_table .
It has 1141580 rows.
I want to convert this into index Organized table. It has no secondary indexes.
How can I convert an existing table to IOT.
CREATE TABLE test_table (
Column1 NUMBER NOT NULL,
Column2 DATE NOT NULL,
Column3 VARCHAR2(100) NOT NULL,
Column4 VARCHAR2(8) NULL,
Column5 VARCHAR2(40) NOT NULL,
Column6 VARCHAR2(3) NULL,
Column7 NUMBER NOT NULL,
Column8 NUMBER NULL,
Column9 VARCHAR2(32) NULL,
ALTER TABLE test_table
ADD CONSTRAINT test_table_pk2 PRIMARY KEY (
Column1,
Column2
USING INDEX
STORAGE (
INITIAL 30720 K
ALTER TABLE test_table
ADD CONSTRAINT test_table_cons1 FOREIGN KEY (
Column1
) REFERENCES test_table2 (
Column1
/alter table doesn't allow to change the organization of a table.
So the logical answer to your question is
You can not
and your question
redundant.
As most other questions here.
So the answer should have been
- create a new table
- insert all rows
- drop the old table
- rename the new table
Oracle is not about rocket science.
Oracle is about reading documentation and using brains.
If you do that, maybe, one day, you will be a bigboy.
If you keep asking redundant questions you will remain a littleboy.
Sybrand Bakker
Senior Oracle DBA -
How can I tell the device is connected to itunes 12?
how can I tell the device is connected to itunes 12? I have Windows 8. I hear that the device is connected, but don't see the device to manage. Only thing that happens is on the phone it says Trust the computer.. I say Trust and nothing happens.
in ituens at the top where you see the small icons for Music, Movies, TV etc when your device is connected you will see a small icon representing your phone or ipad etc popup click that and it will show you the usual interface for backup and syncing.
if that doesnt happen, like it didint for me initially, you should close itunes fully via task manager if you know how to do this and start it again with the device unplugged then plug it in after itunes has finished loading.
Worst case scenario you nee to resatrt -
I have an airport express extending, through wireless, a network provided by an airport extreme. How can I know which clients are connected to my network through express and which are connected through extreme?
Here you can see both routers:
I would expect to some clients connected to the express, other than the extreme. And that's all I see: only the airport extreme appears as client of the airport express.
Below, one can see the summary of the config for both routers.
Would somebody explain it?
Thanks,
Marcelo
Message was edited by: Marcelãoplease disregard this answer.
Message was edited by: Marcelão
Maybe you are looking for
-
Help - Font Book and font Library doesn't work
I've just updated to a new iMac on Yosemite, and Font Book doesn't work. Neither does putting fonts into the "Library" There is a range of fonts that ARE working that are already in either place, but some (that worked up until two days ago in my old
-
How do I get credit for Adobe Touch App purchases?
I purchased two Adobe Touch Apps a few months ago: Photoshop Touch and Ideas. Today I subscribed to Adobe Creative Could and saw that I can get a month free by purchasing three Touch Apps. So, I purchased a third Touch App today, Proto. Okay. Now, ho
-
My compter says there is and apple ipod attached but it is not showing up in itunes and another box pops up and says it needs files then wants me to bowse and find them what do i do? Thanks
-
Dynamic partner link in BPEL2.0 in SOA Suite 11.1.1.6.0
Hi experts, I would like to use the dynamic partner links in BPEL2.0 in SOA Suite 11.1.1.6.0 but I get this error: <env:Fault xmlns:ns0="http://docs.oasis-open.org/wsbpel/2.0/process/executable"> <faultcode>ns0:selectionFailure</faultcode> <fau
-
I have a doubt in ESS applications. What are all the different applications are available in ESS? What should we know about the clients requirement for ESS implementation? Thanks in Advance, Balaji