How to know if a socket connection is open ?
Hi,
I have a ftp class that opens a socket connection to a ftp server. Sometimes the connection is closed and I get an exception. There is any way to know if exists an open connection ?
Thanks !
From SDK v1.3.1 for abstract Class SocketImpl:
Method connect
protected abstract void connect(InetAddress address,
int port)
throws IOException
Connects this socket to the specified port number on the specified host.
Parameters:
address - the IP address of the remote host.port - the port number.Throws:
IOException - if an I/O error occurs when attempting a connection.... So if it throws an exception on inception, it's NOT connected - NOT open, right? This is the class you've subclassed to create the socket connection? If not, which?
Similar Messages
-
How to know if my iphone 4s is open line and can use it anywhere or in any country?,
how to know if my iphone 4s is open line and can use it anywhere or in any country?,like i bougth it in united arab emirates and if im in philippines i can still use it there?.
If you did not purchase it from an authorized distributor, then there is no way to tell short of trying a different SIM. Even then, it may have been hacked to unlock it.
That's a risk you take when you buy from the gray market. -
How can i create a socket connection through an http proxy
i'm trying to make a socket connection send an email - i have code that works when you don't have to go through a proxy server but i can't make it pass the proxy server.
import java.net.*;
import java.io.*;
import java.util.*;
public class Mail
public String to_address = "[email protected]";
public String from_address = "[email protected]";
public String sendSub = "HeHeHe";
public String sendBody = "hehehe - it worked";
// This is created to allow data to be read in by the keyboard.
BufferedReader in = new BufferedReader(
new InputStreamReader(System.in));
private void Mail(String to_address, // recipient's addresses
String from_address, // sender's address
String sendSub, // subject
String sendBody) // Message
throws IOException, ProtocolException, UnknownHostException {
Socket socket; // creates a Socket named socket
PrintStream out; // stream to write to socket
String host = "imap.btopenworld.com"; // identification of the mail server host
// creates a new socket for connection to the mail server
// as well as two variables for the read and write streams
socket = new Socket(host, 25); // opens socket to host on port 25 (SMTP port)
out = new PrintStream(socket.getOutputStream());
// read the initial message
in.readLine();
// Dialog with the mail server
// send HELO to SMTP server HELO command is given by a connecting SMTP host
out.println( "HELO " + host );
out.flush() ;
in.readLine();
// Once we are connected to the mail server we start sending the email...
// send "from"
out.println( "MAIL FROM: " + from_address );
out.flush() ;
in.readLine();
// send "to"
out.println( "RCPT TO: " + to_address );
out.flush() ;
in.readLine();
// prepare the mailserver to receive the data
out.println( "DATA" );
out.flush() ;
in.readLine();
// Send actual email
out.println("From: " + from_address);
out.println("To: " + to_address);
out.println( "Subject: " + sendSub + "\n" );
out.flush() ;
out.println("");
out.println( sendBody ) ;
out.println(".") ; // standard to determine end-of-body
out.flush() ;
in.readLine();
//Quit and closes socket
out.println("QUIT");
out.flush();
in.close() ;
socket.close() ;
return ;
public static void main (String [] args) throws IOException
Mail themail = new Mail();
}i've tried that but it doesn't seem to do nething - this is how i implemented it...
import java.net.*;
import java.io.*;
import java.util.*;
public class Mail
public String to_address = "[email protected]";
public String from_address = "[email protected]";
public String sendSub = "HeHeHe";
public String sendBody = "hehehe - it worked";
// This is created to allow data to be read in by the keyboard.
BufferedReader in = new BufferedReader(
new InputStreamReader(System.in));
private void Mail(String to_address, // recipient's addresses
String from_address, // sender's address
String sendSub, // subject
String sendBody) // Message
throws IOException, ProtocolException, UnknownHostException {
Socket socket; // creates a Socket named socket
PrintStream out; // stream to write to socket
String host = "imap.btopenworld.com"; // identification of the mail server host
// creates a new socket for connection to the mail server
// as well as two variables for the read and write streams
socket = new Socket(host, 25); // opens socket to host on port 25 (SMTP port)
out = new PrintStream(socket.getOutputStream());
// read the initial message
in.readLine();
System.getProperties().put( "proxySet", "true" );
System.getProperties().put( "proxyHost", "144.124.16.28" );
System.getProperties().put( "proxyPort", "8080" );
// Dialog with the mail server
// send HELO to SMTP server HELO command is given by a connecting SMTP host
out.println( "HELO " + host );
out.flush() ;
in.readLine();
// Once we are connected to the mail server we start sending the email...
// send "from"
out.println( "MAIL FROM: " + from_address );
out.flush() ;
in.readLine();
// send "to"
out.println( "RCPT TO: " + to_address );
out.flush() ;
in.readLine();
// prepare the mailserver to receive the data
out.println( "DATA" );
out.flush() ;
in.readLine();
// Send actual email
out.println("From: " + from_address);
out.println("To: " + to_address);
out.println( "Subject: " + sendSub + "\n" );
out.flush() ;
out.println("");
out.println( sendBody ) ;
out.println(".") ; // standard to determine end-of-body
out.flush() ;
in.readLine();
//Quit and closes socket
out.println("QUIT");
out.flush();
in.close() ;
socket.close() ;
return ;
public static void main (String [] args) throws IOException
Mail themail = new Mail();
} -
How to know current speed of connection in Kbps?
Does anyone know how to know the speed of network/internet connection? I couldn't find any member method of JAVA's class that returns this value. Very appreciate for all your hints.
Try something like this:public class Test
public static void main(String[] argv)
try
URL url = new URL("http://java.sun.com"); /* put a pointer to some big image here */
InputStream is = url.openConnection().getInputStream();
int bytes = 0;
long ms = System.currentTimeMillis();
while(is.read() != -1) bytes++;
ms = System.currentTimeMillis() - ms;
double kbps = ((double)bytes / ((double)ms / 1000)) / 1024;
System.out.println("kbps = " + (long)kbps);
System.exit(0);
catch(Throwable t)
t.printStackTrace();
System.exit(-1);
}I suggest you repeat this test for several pointers and take the average... -
How to know Information of a Connection Pool
HI,
I want to know the information of a connection pool for example its maxSize and
what are the active connections in the pool programitically ie. thr' code.
I can monitor them thr' console.But how to monitor a pool thr' code.
And what does all the attributes like WaitSecondsHigh,Waiters,
WaitersHigh mean.how can i get information about them.
And how do i get the information of them thr' code.
I have seen that JDBCConnectionPoolRuntime gives information about the pool.But
how to create a object of this interface.
Can anyone provide me the code for this.
Let me explain more....
I have created a demo pool and has set the maximum connections size as 2.I tried
to get 3 connections from the pool and obvious a exception has raised.(java.sql.SQLException:
Pool connect failed: weblogic.common.ResourceException: None available).
so i am writing a class such that it keeps the connections in wait state when
the pool has reached its maximum value for which i should know what are the active
connections and the maximum size of the pool.
So please if any one can help me how to know these values of the connetion pool
programitically,it would be great.Ventak:
This is a sample code i wrote some time ago.
import weblogic.management.MBeanHome;
import weblogic.management.WebLogicMBean;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.AuthenticationException;
import javax.naming.CommunicationException;
import weblogic.jndi.Environment;
import java.util.Collection;
import java.util.Iterator;
import weblogic.management.runtime.JDBCConnectionPoolRuntimeMBean;
import weblogic.management.configuration.JDBCConnectionPoolMBean;
import weblogic.management.WebLogicObjectName;
public class mbean
public static void main(String args[])
MBeanHome home = null;
try
Environment env = new Environment();
env.setProviderUrl(url);
env.setSecurityPrincipal(username);
env.setSecurityCredentials(password);
Context ctx = env.getInitialContext();
home = (MBeanHome) ctx.lookup(MBeanHome.JNDI_NAME+".wlcsServer");
// Note the type of the Mbean: JDBCConnectionPoolConfig - The fixed
configuration of the pool just as the console
// JDBCConnectionPoolRuntime - The runtime parameters of the pool, like
current connections
// To retrieve the Mbean JDBCConnectionPoolMBean via ObjectName
WebLogicObjectName o = new
WebLogicObjectName("commercePool","JDBCConnectionPoolConfig","wlcsDomain","w
lcsServer");
JDBCConnectionPoolMBean pool = (JDBCConnectionPoolMBean)home.getMBean(o);
// the same Mbean but without ObjectName
JDBCConnectionPoolMBean pool =
(JDBCConnectionPoolMBean)home.getMBean("ccPoolSuc","JDBCConnectionPoolConfig
System.out.println("TableName " + pool.getTestTableName());
// To retrieve the JDBCConnectionPoolRuntimeMBean
JDBCConnectionPoolRuntimeMBean poolR =
(JDBCConnectionPoolRuntimeMBean)home.getMBean(new
WebLogicObjectName("wlcsDomain:ServerRuntime=wlcsServer,Name=sucPool,Locatio
n=wlcsServer,Type=JDBCConnectionPoolRuntime"));
System.out.println("getActiveConnectionsCurrentCount()" +
poolR.getActiveConnectionsCurrentCount());
// To retrieve a collection of the Mbeans by Type
Collection Beans = home.getMBeansByType("JDBCConnectionPoolRuntime");
catch(Exception ex)
System.out.println("Error " + ex);
ex.printStackTrace();
return;
These are extracts of the actual code, providing you diferent ways.
By the way, the issue you are trying to solve with a waiting time for a
connection to be available is an out-of-the-box functionality of the
weblogic pool. But is also restricted to some like 5 secs. (if i remember
well) and the reason is to avoid thread contention.
So if you are going to implement some like that must be much carefull. The
better way is to play with the InitialCapacity, MaxCapacity,
CapacityIncrement and ShrinkPeriod parameters, giving the enough connections
to avoid as possible as you can the situation in which exists waiters of
connections.
Hope this help.
"Venkat Raghava Moganti" <[email protected]> wrote in message
news:[email protected]...
>
HI,
I want to know the information of a connection pool for example itsmaxSize and
what are the active connections in the pool programitically ie. thr' code.
I can monitor them thr' console.But how to monitor a pool thr' code.>
And what does all the attributes like WaitSecondsHigh,Waiters,
WaitersHigh mean.how can i get information about them.
And how do i get the information of them thr' code.
I have seen that JDBCConnectionPoolRuntime gives information about thepool.But
how to create a object of this interface.
Can anyone provide me the code for this.
Let me explain more....
I have created a demo pool and has set the maximum connections size as 2.Itried
to get 3 connections from the pool and obvious a exception hasraised.(java.sql.SQLException:
Pool connect failed: weblogic.common.ResourceException: None available).
so i am writing a class such that it keeps the connections in wait statewhen
the pool has reached its maximum value for which i should know what arethe active
connections and the maximum size of the pool.
So please if any one can help me how to know these values of the connetionpool
programitically,it would be great. -
How to change HttpURLConnection to socket connection in java
hello i have a problem about a socket connection can you help me
i want to change HttpURLConnection connection to socket connection
here is
java.net.URL url = new java.net.URL("http://64.74.75.74/approot/webapp/ZOR/bare");
connection = new sun.net.www.protocol.http.HttpURLConnection(url, " ", 0);
connection.setRequestMethod("POST");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(connection.getOutputStream());
out.writeObject(getTextFieldGiden().getText());
out.flush();
out.close();
return (String) (new java.io.ObjectInputStream(connection.getInputStream()).readObject());
how can i change it to
socket connection
thank you very muchThe class you mention uses a Socket connection.
If you read the source you will see how it does it.
If you use a debugger yu will see the code which is most relevent. -
How to know if the pdf file is opened.
Hi,
on my web site I have many pages containing hundrend of url pointing to the pdf documents.
The problem is how I can know that the pdf file was open or downloaded by user ( I used session for this task). I have to point out that I did not integrate in my page any javascript action on those documents.
This point will help me to solve some historical access on the web site.
Thank youYour best bet would be to create a filter that will handle access to pdf files. This filter would be bound to /*.pdf and can have access to the users HttpSession object so you are able to find out who requested this file and logic it how ever you wish.
I Hope this helps
-Richard Burton -
How to know that remote object connection with server has not disconnected?
Hi,
In my application want to check weather connnection with
remote object has disconnected or not. I have not found any
property with remoteobject to verify this. Weather it is possible
with remote object or if not then how it could be done with
channel. I have checked connected property of channel but i could
not find out how it works.
Is there any solution for this, if any one know please
reply...
Thanks..Did you ever get resolved. I am having the sames issues
Regards,
Wally
http://www.level10solutions.com -
How to know the Phone ID connected to a PC ?
Hi, I want to know if it's possible to know from a PC desktop, in what Phone this PC is connected ?
The exact same scenario has been discussed just a few posts down: http://forums.cisco.com/eforum/servlet/NetProf;jsessionid=rnvoktpv51.SJ1A?page=netprof&forum=IP%20Communications%20and%20Video&topic=IP%20Phone%20Services%20for%20Developers&CommCmd=MB%3Fcmd%3Ddisplay_location%26location%3D.1ddb1ea2
-
How to know speed of internet connection
How can you see the speed of your internet connection either wirelessley or LAN?
http://www.speedtest.net/
http://www.speakeasy.net/speedtest/
http://www.bandwidthplace.com/
Best of luck. -
How to know what ActiveX references are still open
Okay, so I'm about the millionth person to post about this topic, but I feel like I know what I should be doing, but have hit a wall. I have read through pretty much everything I could find in the forums about references and ActiveX.
I am communicating with Excel via ActiveX, and everything works seemlessly, until I realized that if the user closes the Excel sheet (via an "exit" button on my FP), the "EXCEL.exe" process is still running. I've read enough to know that this probably points to a reference that I have not closed.
Problem is, I have poured over my code, and as far as I can tell, I have closed every reference, in the opposite order it was opened (as I read to do in a post earlier).
Aside from casting references to int's to see what is still considered "active" (as I mentioned earlier, all the ones I can find are closed, so this doesn't help me), is there a way to determine which ActiveX references are still open?
Even a way outside of LV? A Microsoft utility even or ...well anything! This is very annoying, and I know it should be quick and easy, I just have to know what is remaining open.
Or, am I missing something else that might be keeping EXCEL.exe running? (yes, I have an application quit and close the application reference)
Thanks for any helpHi Will,
As you said it yourself closing the same number of references as you open and using Application Quit should be enough to close down Excel.exe.
Did you run your code in highlight execution to see how the behavior of your program changes when you hit the "Exit" button on your Front Panel?
If you can post the minimum amount of code that reproduces the error, I will be more than happy to take a look at it.
Best regards,
Message Edited by Kalin T on 12-07-2006 03:11 PM
Kalin T.
National Instruments
Attachments:
activex_excel.jpg 16 KB -
How we know whether a production order is open or clos
Hi,
Anybody can tell me how we can know that whether a production order is open or close?
Thanks,
AparnaHi,
In addition to 1st reply if your order status is TECO ,Clsed,Lcked then your order is closed .In this status you can open this order for any use.
TECO -Technically complete .
Closed -closed for any use.
Locked -Again same locked for any further process.
Regards
SANIL -
Hi pal,
Is there anyThing in API to know if a sent email has been opened or deleted by reciever?
AsifHi,
Even i am having a similar problem..
I want to track the emails sent out from my application.
Whether the mails are read or not and if read for how long they are read???
Can anyone give me an idea abt this.
Thank u -
How do i get Iphoto to connect and open
Iphoto will not respond and will not open how do i fix
Remember: we cannot see your machine. There are 9 different versions of iPhoto and they run on 8 different versions of the Operating System. The tricks and tips for dealing with issues vary depending on the version of iPhoto and the version of the OS. So to get help you need to give as much information as you can. Basic things like :
- What version of iPhoto.
- What version of the Operating System.
- Details. As full a description of the problem as you can. For instance: 'iPhoto won't export' is best explained by describing how you are trying to export, and so on.
- History: Is this going on long? Has anything been installed or deleted?
- Are there error messages?
- What steps have you tried already to solve the issue.
- Anything unusual about your set up? Or how you use iPhoto?
Anything else you can think of that might help someone understand the problem you have.
Posts that consist of "iPhoto doesn't work. Help" or "iPhoto won't print" or "Suddenly I have no photos!!!!!!!!!!" mean that any helper is simply guessing. More information means you get better assistance. -
How to know if a UDF form is opened else then using a TRY CATCH ?
I'm looking for any way to find out if the UDF form is visible
else then trying to open it in a try catch and if it's not sending a key. This if very ugly, slow and not really my kind.
I tried to iterate through all the forms in SBO_Application.Forms but it's not there. All I see is the main form
I just need to make sure the UDF form is visible when Inventory form is loaded so I can put a value in one of the UDF
If there's a better way I'm buying itHi Marc,
Rather than putting your data in the UDF in the UDF side form, you can add a control to the main form (during the load event of the form) and bind this to the UDF through the DBDataSource that is already available on the main form. This means that you don't need to worry about whether the UDF form is open or not because you can always read or write to your UDF data from the main form.
Alternatively, the UDF form TypeEx property is always the same as the main form but with a minus sign in front. Therefore, if you know the TypeEx and FormTypeCount of the main form then you can use the GetForm method of the Application object to get the UDF form.
oForm = _sboApp.Forms.GetForm("-" + oMainForm.TypeEx, oMainForm.TypeCount);
You'd still need a try/catch around this and if it raises an error then activate the 6913 menu to open the UDF form.
Kind Regards,
Owen
Maybe you are looking for
-
Hi all, I've got procedure for inserting data into value1 column of table1. My need is to determine data type entered by user. If data type is not number then user should receive error. How do I perform it?
-
How can I create the Device allocations[EG42]?
Hy, I want a requirement to create the deviceallocation in background. The device is insert in a installation. The following listing dosn't work. Has anybody a idea, why not? MOVE: i_anlage TO l_anlage. MOVE: i_ab TO l_ab. MOVE: i
-
Reusing images within a content area
I have uploaded images into a content area with intent to reuse them within the same content area in different folders. However, I have been unsuccessful. How do I reuse an already uploaded image? Ex: I want to display a logo in each folder without h
-
5700 New FirmWare???
Hey Guys I bought New Nokia 5700 Xpress Music Please Tell Me That When Nokia Will Release It's Newer Firmware I have v03.27 And Can ANy One Tell Me The Best Configuration for Loud SOund ALthogh It's SOund Is Rocking But please Tell ME The Best Config
-
Experts, Can you tell me the steps to do the GR(Goods Receipt) against the Material(Receiving Materials). I want to findout the open periods.