Socket programming usin nio package
hello frens i m new to socket programming
i come to know that nio packaage provides more sophisticated and efficient API to deal with socket programming issue
I need to know where i can get tutorial about socket programming using nio pacakage
Try google
http://www.google.co.uk/search?q=java+nio+tutorial
Similar Messages
-
File descriptor leak in socket programming
We have a complex socket programming client package in java using java.nio (Selectors, Selectable channel).
We use the package to connect to a server.
Whenever the server is down, it tries to reconnect to the server again at regular intervals.
In that case, the number of open file descriptors build up with each try. I am able to cofirm this using "pfile <pid>" command.
But, it looks like we are closing the channels, selectors and the sockets properly when it fails to connect to the server.
So we are unable to find the coding that causes the issue.
We run this program in solaris.
Is there a tool to track down the code that leaks the file descriptor.
Thanks.Don't close the selector. There is a selector leak. Just close the socket channel. As this is a client you should then also call selector.selctNow() to have the close take final effect. Otherwise there is also a socket leak.
-
Java.nio package Runtime error java.lang.UnsupportedClassVersionError.
Hi
I am using nio package and create a java program for file locking (FileLocking.java).
Here is the sample
try {
file = new File("C:/acc.txt");
channel = new RandomAccessFile(file, "rw").getChannel();
lock = channel.lock(0, Long.MAX_VALUE, true);
try {
lock = channel.tryLock(0, Long.MAX_VALUE, true);
catch (OverlappingFileLockException e) {
return true;
using wsad 5.1 and jdk1.4 i compiled this program.
While executing i got the following runtime error..
java.lang.UnsupportedClassVersionError: FileLocking (Unsupported major.minor version 48.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:703)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:133)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:319)
at java.net.URLClassLoader.access$400(URLClassLoader.java:92)
at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:677)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:238)
at java.lang.ClassLoader.loadClass(ClassLoader.java:516)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:441)
at java.lang.ClassLoader.loadClass(ClassLoader.java:448)
Exception in thread "main"
Even if i try to recompile it in command prompt and run, i got the same error.
please suggest me how can i overcome this problem.UnsupportedClassVersionError means that you are trying to execute a class for a newer version of the JVM on an older version of the JVM.
Version 48.0 is for Java 1.4, so you have compiled your class with JDK 1.4.
The computer you are trying to run the class on, has an older version of Java than 1.4 - check it!
Try recompiling your source files with the "-target" switch, for example if you're running on Java 1.3, try compiling with:
javac -target 1.3 ... FileLocking.java -
Simple Socket Programming, But,.......
This code is Server, Client Socket program code.
Client send data to server and then, Server get data and save it
to file in server.
I think client works well.
But, Server.java file have some problem.
It generate ClassNotFoundException!
So the result file have garbage value only.
Any idea please................
/////////////////////////// Server.java /////////////////////////////////
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Server extends JFrame
private JTextField enter;
private JTextArea display;
ObjectInputStream input;
ObjectOutputStream output;
FileOutputStream resultFile;
public Server(){
super("Server");
Container c = getContentPane();
enter = new JTextField();
enter.setEnabled(false);
enter.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent ev){
//None
c.add(enter, BorderLayout.NORTH);
display = new JTextArea();
c.add(new JScrollPane(display),
BorderLayout.CENTER);
setSize(300, 150);
show();
public void runServer(){
ServerSocket server;
Socket connection;
int counter = 1;
display.setText("");
try{
server = new ServerSocket(8800, 100);
while(true){
display.append("Waiting for connection\n" + counter);
connection = server.accept();
display.append("Connection " + counter +
"received from: " + connection.getInetAddress().getHostName());
resultFile = new FileOutputStream("hi.txt");
output = new ObjectOutputStream(resultFile);
output.flush();
input = new ObjectInputStream(
connection.getInputStream()
display.append("\nGod I/O stream, I/O is opened\n");
enter.setEnabled(true);
DataForm01 data = null;
try{
data = (DataForm01) input.readObject();
output.writeObject(data);
data = (DataForm01) input.readObject();
output.writeObject(data);
catch(NullPointerException e){
display.append("Null pointer Exception");
catch(ClassNotFoundException cnfex){
display.append("\nUnknown Object type received");
catch(IOException e){
display.append("\nIOException Occured!");
if(resultFile != null){
resultFile.flush();
resultFile.close();
display.append("\nUser Terminate connection");
enter.setEnabled(false);
input.close();
output.close();
connection.close();
++counter;
catch(EOFException eof){
System.out.println("Client Terminate Connection");
catch(IOException io){
io.printStackTrace();
display.append("File is created!");
public static void main(String[] args){
Server app = new Server();
app.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
app.runServer();
/////////////////////////// client.java /////////////////////////////////
* Client.java
* @author Created by Omnicore CodeGuide
package Client;
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Client extends JFrame
private JTextField enter;
private JTextArea display;
ObjectOutputStream output;
String message = "";
//DataForm01 dfrm[];
public Client(){
super("Client");
Container c = getContentPane();
enter = new JTextField();
enter.setEnabled(false);
enter.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
//None.
c.add(enter, BorderLayout.NORTH);
display = new JTextArea();
c.add(new JScrollPane(display), BorderLayout.CENTER);
setSize(300, 150);
show();
public void runClient(){
Socket client;
try{
display.setText("Attemption Connection...\n");
client = new Socket(InetAddress.getByName("127.0.0.1"), 8800);
display.append("Connected to : = " +
client.getInetAddress().getHostName());
output = new ObjectOutputStream(
client.getOutputStream()
output.flush();
display.append("\nGot I/O Stream, Stream is opened!\n");
enter.setEnabled(true);
dfrm = new DataForm01[10];
for(int i=0; i<10; i++){
dfrm[i] = new DataForm01();
dfrm.stn = i;
dfrm[i].name = "Jinbom" + Integer.toString(i);
dfrm[i].hobby = "Soccer" + Integer.toString(i);
dfrm[i].point = (double)i;
for(int i=0; i<10; i++){
try{
output.writeObject(dfrm[i]);
display.append(dfrm[i].getData());
catch(IOException ev){
display.append("\nClass is not founded!\n");
DataForm01 dfrm = new DataForm01();
dfrm.stn=1;
dfrm.name="Jinbom";
dfrm.hobby = "Soccer";
dfrm.point = (double)0.23;
DataForm01 dfrm02 = new DataForm01();
dfrm02.stn = 1;
dfrm02.name = "Jimbin";
dfrm02.hobby = "Soccer";
dfrm02.point = 0.4353;
try{
output.writeObject(dfrm);
display.append(dfrm.getData());
output.writeObject(dfrm02);
display.append(dfrm.getData());
catch(IOException ev){
display.append("\nClass is not founded!\n");
if(output != null) output.flush();
display.append("Closing connection.\n");
output.close();
client.close();
catch(IOException ioe){
ioe.printStackTrace();
public static void main(String[] args){
Client app = new Client();
app.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
app.runClient();
/////////////////////////// DataForm01.java /////////////////////////////////
import java.io.*;
public class DataForm01 implements Serializable
int stn;
String name;
String hobby;
double point;
public String getData(){
return Integer.toString(stn) + name + hobby + Double.toString(point);This is indented code. ^^;
It's better to view.
////////////////////////// Server.java /////////////////////////////////////////
* Server.java
* @author Created by Omnicore CodeGuide
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Server extends JFrame
private JTextField enter;
private JTextArea display;
ObjectInputStream input;
ObjectOutputStream output;
FileOutputStream resultFile;
public Server(){
super("Server");
Container c = getContentPane();
enter = new JTextField();
enter.setEnabled(false);
enter.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent ev){
//None
c.add(enter, BorderLayout.NORTH);
display = new JTextArea();
c.add(new JScrollPane(display),
BorderLayout.CENTER);
setSize(300, 150);
show();
public void runServer(){
ServerSocket server;
Socket connection;
int counter = 1;
display.setText("");
try{
server = new ServerSocket(8800, 100);
while(true){
display.append("Waiting for connection\n" + counter);
connection = server.accept();
display.append("Connection " + counter +
"received from: " + connection.getInetAddress().getHostName());
resultFile = new FileOutputStream("hi.txt");
output = new ObjectOutputStream(resultFile);
output.flush();
input = new ObjectInputStream(
connection.getInputStream()
display.append("\nGod I/O stream, I/O is opened\n");
enter.setEnabled(true);
DataForm01 data = null;
for(int i=0; i<10; i++){
try{
data = (DataForm01) input.readObject();
if(data == null) break;
output.writeObject(data);
catch(NullPointerException e){
display.append("Null pointer Exception");
catch(ClassNotFoundException cnfex){
display.append("\nUnknown Object type received");
catch(IOException e){
display.append("\nIOException Occured!");
DataForm01 data = null;
try{
data = (DataForm01) input.readObject();
output.writeObject(data);
data = (DataForm01) input.readObject();
output.writeObject(data);
catch(NullPointerException e){
display.append("Null pointer Exception");
catch(ClassNotFoundException cnfex){
display.append("\nUnknown Object type received");
catch(IOException e){
display.append("\nIOException Occured!");
if(resultFile != null){
resultFile.flush();
resultFile.close();
display.append("\nUser Terminate connection");
enter.setEnabled(false);
input.close();
output.close();
connection.close();
++counter;
catch(EOFException eof){
System.out.println("Client Terminate Connection");
catch(IOException io){
io.printStackTrace();
display.append("File is created!");
public static void main(String[] args){
Server app = new Server();
app.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
app.runServer();
////////////////////////// Client.java /////////////////////////////////////////
* Client.java
* @author Created by Omnicore CodeGuide
package Client;
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Client extends JFrame
private JTextField enter;
private JTextArea display;
ObjectOutputStream output;
String message = "";
//DataForm01 dfrm[];
public Client(){
super("Client");
Container c = getContentPane();
enter = new JTextField();
enter.setEnabled(false);
enter.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
//None.
c.add(enter, BorderLayout.NORTH);
display = new JTextArea();
c.add(new JScrollPane(display), BorderLayout.CENTER);
setSize(300, 150);
show();
public void runClient(){
Socket client;
try{
display.setText("Attemption Connection...\n");
client = new Socket(InetAddress.getByName("127.0.0.1"), 8800);
display.append("Connected to : = " +
client.getInetAddress().getHostName());
output = new ObjectOutputStream(
client.getOutputStream()
output.flush();
display.append("\nGot I/O Stream, Stream is opened!\n");
enter.setEnabled(true);
dfrm = new DataForm01[10];
for(int i=0; i<10; i++){
dfrm[i] = new DataForm01();
dfrm.stn = i;
dfrm[i].name = "Jinbom" + Integer.toString(i);
dfrm[i].hobby = "Soccer" + Integer.toString(i);
dfrm[i].point = (double)i;
for(int i=0; i<10; i++){
try{
output.writeObject(dfrm[i]);
display.append(dfrm[i].getData());
catch(IOException ev){
display.append("\nClass is not founded!\n");
DataForm01 dfrm = new DataForm01();
dfrm.stn=1;
dfrm.name="Jinbom";
dfrm.hobby = "Soccer";
dfrm.point = (double)0.23;
DataForm01 dfrm02 = new DataForm01();
dfrm02.stn = 1;
dfrm02.name = "Jimbin";
dfrm02.hobby = "Soccer";
dfrm02.point = 0.4353;
try{
output.writeObject(dfrm);
display.append(dfrm.getData());
output.writeObject(dfrm02);
display.append(dfrm.getData());
catch(IOException ev){
display.append("\nClass is not founded!\n");
if(output != null) output.flush();
display.append("Closing connection.\n");
output.close();
client.close();
catch(IOException ioe){
ioe.printStackTrace();
public static void main(String[] args){
Client app = new Client();
app.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
app.runClient();
////////////////////////// DataForm01.java /////////////////////////////////////////
* DataForm01.java
* @author Created by Omnicore CodeGuide
import java.io.*;
public class DataForm01 implements Serializable
int stn;
String name;
String hobby;
double point;
public String getData(){
return Integer.toString(stn) + name + hobby + Double.toString(point); -
Can someone share with me a benefit of using .nio package
I'm trying to learn the nio package.
I was wondering if someone would be so kind as to share with me an example of something interesting that can be done with nio that is either new or a signficiant speed boost
stephencould you please explain for me why i would want to
read to thousands of network sockets at a time
No. I can just tell you what it is good for. I don't know who you are, so how could I possibly know your wants and desires?
>
and how I would be able to do so without worrying
about blocking ? Because you can set it up to be non-blocking. -
File Locking using java.nio package
I am trying to lock a file using FileChannel's lock method on a CIFS file system. My application is on windows and the CIFS is accessed using UNC format ( \\1.2.3.4\blah.. ). I get the following error
java.io.IOException: The network request is not supported
at sun.nio.ch.FileChannelImpl.lock0(Native Method)
at sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:750)
at java.nio.channels.FileChannel.lock(FileChannel.java:865)
From the same machine using the same UNC formatm, when I lock the file using windows C API, I can successfull lock.
Anyone has any idea why JVM can not lock even using nio package. Shouldnt it use the same ( or similar ) API under the hood as its clear by the package name java.nio
The C program I am using is
#include <io.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/locking.h>
#include <share.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main( int argc, char **argv )
int fh,numread;
char buffer[40];
char filename[500];
/* Quit if can't open file or system doesn't
* support sharing.
if ( argc > 1 )
strcpy(filename,argv[1]);
else
strcpy(filename,"locking.c");
fh = sopen(filename , O_RDWR, SHDENYNO, //_SH_DENYRW,
SIREAD | SIWRITE );
if( fh == -1 )
exit( 1 );
/* Lock some bytes and read them. Then unlock. */
if( locking( fh, LKNBLCK, 30L ) != -1 )
printf( "No one can change these bytes while I'm reading them\n" );
numread = _read( fh, buffer, 30 );
printf( "%d bytes read: %.30s\n", numread, buffer );
lseek( fh, 0L, SEEK_SET );
printf( "Press a key to unlock the file.....\n" );
getchar();
locking( fh, LKUNLCK, 30L );
printf( "Now I'm done. Do what you will with them\n" );
else
perror( "Locking failed\n" );
_close( fh );
}It uses LockFile and LockFileEx. Please check in the MSDN documentation the peculiarities of such APIs.
JNIEXPORT jint JNICALL
Java_sun_nio_ch_FileChannelImpl_lock0(JNIEnv *env, jobject this, jobject fdo,
jboolean block, jlong pos, jlong size,
jboolean shared)
jint fd = fdval(env, fdo);
HANDLE h = (HANDLE)_get_osfhandle(fd);
DWORD lowPos = (DWORD)pos;
long highPos = (long)(pos >> 32);
DWORD lowNumBytes = (DWORD)size;
DWORD highNumBytes = (DWORD)(size >> 32);
jint result = 0;
if (onNT) {
DWORD flags = 0;
OVERLAPPED o;
o.hEvent = 0;
o.Offset = lowPos;
o.OffsetHigh = highPos;
if (block == JNI_FALSE) {
flags |= LOCKFILE_FAIL_IMMEDIATELY;
if (shared == JNI_FALSE) {
flags |= LOCKFILE_EXCLUSIVE_LOCK;
result = LockFileEx(h, flags, 0, lowNumBytes, highNumBytes, &o);
if (result == 0) {
int error = GetLastError();
if (error != ERROR_LOCK_VIOLATION) {
JNU_ThrowIOExceptionWithLastError(env, "Lock failed");
return sun_nio_ch_FileChannelImpl_NO_LOCK;
if (flags & LOCKFILE_FAIL_IMMEDIATELY) {
return sun_nio_ch_FileChannelImpl_NO_LOCK;
JNU_ThrowIOExceptionWithLastError(env, "Lock failed");
return sun_nio_ch_FileChannelImpl_NO_LOCK;
return sun_nio_ch_FileChannelImpl_LOCKED;
} else {
for(;;) {
if (size > 0x7fffffff) {
size = 0x7fffffff;
lowNumBytes = (DWORD)size;
highNumBytes = 0;
result = LockFile(h, lowPos, highPos, lowNumBytes, highNumBytes);
if (result != 0) {
if (shared == JNI_TRUE) {
return sun_nio_ch_FileChannelImpl_RET_EX_LOCK;
} else {
return sun_nio_ch_FileChannelImpl_LOCKED;
} else {
int error = GetLastError();
if (error != ERROR_LOCK_VIOLATION) {
JNU_ThrowIOExceptionWithLastError(env, "Lock failed");
return sun_nio_ch_FileChannelImpl_NO_LOCK;
if (block == JNI_FALSE) {
return sun_nio_ch_FileChannelImpl_NO_LOCK;
Sleep(100);
return sun_nio_ch_FileChannelImpl_NO_LOCK;
} -
TCP/IP socket programming in ABAP
Hi,
Is there any method of TCP socket programming in ABAP? For example is there any function module for creating a socket for a IP address and port number. After that, is it possible to send binary/text data to a connected IP/port destination. I need such a solution because I need to send raw data (native commans) to barcode printer on our network which has a static IP address and listens incoming data through a fixed port number specified in its documentation. For a solution, I coded some .NET VB and built a small application that acts as a RFC server program which can be called by SAP according to definitions I made in SM59 (I defined a new TCP connection and it works well sometimes!). In this application, data coming from SAP are transferred to the barcode printer. This is achived by the .NET Socket class library. This solution works well but after a few subsequent call from SAP, connection hangs! SAP cannot call the application anymore, I test the connection in SM59 and it also hangs, so I need to restart the VB application, but this is unacceptable in our project.
As a result, I decided to code the program that will send data to the printer in ABAP as a function module or subroutine pool, so is there any way to create a socket in ABAP and connect to specific IP/port destination? I searched for possible function modules in SE37 and possible classes in SE24 but unfortunately I could not find one. For example, do know any kind of system function in ABAP (native commands executed by CALL statement), that can be used for this purpose?
I would appreciate any help,
Kind regards,
Tolga
Edited by: Tolga Togan Duz on Dec 17, 2007 11:49 PMHi,
I doubt that there is a low level API for sockets in ABAP. There is API for HTTP but probably that won't help you. As a workaround you can use external OS commands (transactions SM69 and SM49). For example on Unix you can use netcat to transfer file. Your FM needs to dump data into folder and then call netcat to transfer file.
Cheers -
Java Swing and Socket Programming
I am making a Messenger like yahoo Messenger using Swing and Socket Programming ,Multithreading .
Is this techology feasible or i should try something else.
I want to display my messenger icon on task bar as it comes when i install and run Yahoo Messenger.
Which class i should use.I don't really have an answer to what you are asking. But I am developing the same kind of application. I am using RMI for client-server and server-server (i have distributed servers) communication and TCP/IP for client-client. So may be we might be able to help each other out. My email id is [email protected]
Are you opening a new socket for every conversation? I was wondering how to multithread a socket to reuse it for different connections, if it is possible at all.
--Poonam. -
Network and socket programming in python
i want to learn network and socket programming but i would like to do this in python.Reason behind this is that python is very simple and the only language i know .
anybody can suggest me which book should i pick.
the book should have following specification--
1)not tedious to follow
2)lots of example
3)starts with some networking stuff and then get into codes
thanks in advance with regards.hmm. well, your requirements are almost contradictory.
Not sure about books, except maybe dusty's.
Most python books cover at least some network programming (unless the book is topic specific).
I use lots of python-twisted at work. I mean ALOT. I wouldn't recommend it to someone looking for non-tedious though! I also like gevent/eventlet (esp. the async socket wrappers).
EDIT: Wow. My post wasn't really helpful at all. Sorry!
Last edited by cactus (2010-09-04 09:16:54) -
Socket Programing in J2ME - Confused with Sun Sample Code
Hai Everybody,
I have confused with sample code provided by Sun Inc , for the demo of socket programming in J2ME. I found the code in the API specification of J2ME. The code look like :-
// Create the server listening socket for port 1234
ServerSocketConnection scn =(ServerSocketConnection) Connector.open("socket://:1234");
where Connector.open() method return an interface Connection which is the base interface of ServerSocketConnection. I have confused with this line , is it is possible to cast base class object to the derived class object?
Plese help me in this regards
Thanks in advance
SulfikkarThere is nothing to be confused about. The Connector factory creates an implementation of one of the extentions of the Connection interface and returns it.
For a serversocket "socket://<port>" it will return an implementation of the ServerSocketConnection interface. You don't need to know what the implementation looks like. You'll only need to cast the Connection to a ServerSocketConnection . -
Hi,
I have been given a new project whereby I have to:
1) Write a class with a method that takes as an argument an xml document, communicate s with a SOAP server and return the SOAPs response (in this case a ResponseWrapper object).
2) This then has to be implemented as a Daemon, that listens to a particular socket.
The reason for this being is that it can be uploaded to a server, allowing a pearl program to send the XML to the Daemon, have this contact the SOAP server and then return the SOAPs response back to the pearl program.
I am aware that this sounds unnecessarily complicated but it does have to be implemented this way.
I have written the class and it successfully communicates with the SOAP server and returns a response, but have no idea how to implement it as a Daemon and have had no experience with socket programming.
Could anyone point me to a tutorial or give me some pointers in how to get started?
Thanks,It was an option to use a Web Service, but I was told
that due to security issues it would take to long to
write all the necessary checks and interceptors
(which I know how to do), so I should implement it
this way (which I don't know how to do); since it is
sitting behind the firewall it would not be
accessible for spoofing.Huh? You realize that tons of very sensitive information is transmitted all over the internet using Web Services right?
I have had no experience
with implementing this type of thing before, What is your level of experience then? This may be over your head. I'm not saying that sockets and daemons are advanced concepts, but I wouldn't throw a beginner into that task. -
[Urgent]3G Socket programming
May I use socket for 3G networks?
I use the demo provided by the WTK2.5-Beta(NetworkDemo), it works well in the simulator. However, when I download the program to the mobile phone, it seems that the mobile phone that runs ServerSocket cannot create the socket ... all the 2 handsets use a 3G SIM card provided by a Hong Kong ISP smartTone ... What can I do?
Please help~ provide any web page of codes, thanks very much!1. We want to create a socket connection which can
remain open and live for ever till it is closed. Is
this possible in java socket programming?Yes, but it isn't practical in the real networking world. So your code had better be prepared to deal with network failures.
2. I am just wondering in order to communicate with
the third party over the socket connection, does this
other party requires to run something specific on
their end? I am not able to understand how will my
java code communicate with their server otherwise.It has nothing to do with java. Sockets send and recieve messages. The applications at either end, regardless of the language that they are written in, must handle those messages.
3. Can we send and receive data over the socket
created and also is their specific format for the
data? Yes.
Can we send files of data over this connection?Yes. (Although I don't know why you would need to do that if you are doing credit card auths.)
It would be great if someone can comment on these
questions and also if possible please provide some
code that can create socket connection.The tutorial.....
http://java.sun.com/docs/books/tutorial/networking/sockets/index.html -
Can i run UDP client and UDP server socket program in the same pc ?
hi all.
when i execute my UDP client socket program and UDP server socket program in the same pc ,
It's will shown the error msg :
"Address already in use: Cannot bind"
but if i run UDP client socket program in the remote pc and UDP server socket program run in local pc , it's will success.
anybody know what's going on ?
any help will be appreciated !bobby92 wrote:
i have use a specified port for UDP server side , and for client define the server port "DatagramSocket clientSocket= new DatagramSocket(Server_PORT);"Why? The port you provide here is not the target port. It's the local port you listen on. That's only necessary when you want other hosts to connect to you (i.e. when you're acting as a server).
The server should be using that constructor, the client should not be specifying a port.
so when i start the udp server code to listen in local pc , then when i start UDP client code in local pc ,i will get the error "Address already in use: Cannot bind"Because your client tries to bind to the same port that the server already bound to. -
RESTFUL Web Services vs Socket Programming Performance
Hi guys,
I will have an application which will have a service serving about to 30 million users/day and a mean of 5 requests/user.
It means that there will be about 150 million requests per day. I will have two servers behind a load balancer and my clients will be both Java and C++.
I think to implement RESTFUL Web Services but afraid of performance issues.
Did you have a knowledge about the performances of web service and socket programming in such a high loaded project?
Tnx.
Ayberkayberkcansever wrote:
Hi guys,
I will have an application which will have a service serving about to 30 million users/day and a mean of 5 requests/user.
It means that there will be about 150 million requests per day. I will have two servers behind a load balancer and my clients will be both Java and C++.
I think to implement RESTFUL Web Services but afraid of performance issues.
Did you have a knowledge about the performances of web service and socket programming in such a high loaded project?It depends on the CPUs, RAM, disks, and network configurations of those servers.
It depends on how the requests are distributed throughout the day.
It depends on how big the requests are and how big the responses are. -
HELP : Convert socket programming from Ipv4 to IPv6
Hi all,
I need help in converting my Ipv4 socket programing to Ipv6. How can I do this? I already have an Ipv4 socket programming that is working but when I tried to convert it to Ipv6 it doesn't work .
this is my Ipv4 socket programming :
DatagramPacket sendPacket;
DatagramSocket sock;
ip = jtfDIP.getText().trim();
try{
sock = new DatagramSocket();
add = InetAddress.getByName(ip);
sendPacket = new DatagramPacket(buf,buf.length,add,port);
Please help me. How can I convert this to Ipv6. Thank you.Socket sock = new Socket("host");
or
Socket sock = new Socket("192.168.1.1");
or
Socket sock = new Socket("www.host.com");
or
Socket sock = new Socket("hhhh.hhhh.hhhh.hhhh");
Get it? Just use whatever host, domain name, or IP you need, the underlying native code does the work - you'll never need to do anything, for the most part.
Maybe you are looking for
-
Dear all, I get results in rows & columnwise in ALV report. Suppose I select any field & double click , I want to call any function further. Pl' tell the example how to give this event action in code ?? Pl ' give sample examples..... Thanks..
-
Newbie in SQL Developer: misc questions
Hello, I´m new to SQL Developer, always worked with Quest´s SQL Navigator before. 1.) I have a file.sql with following instructions: begin package_1.variable_1:='T'; package_2.procedure_1; package_2.procedure_2; package_2.procedure_3; end; In Quest S
-
I just bought an Ipad and it is in Chinese. How do I get it to English?
How do I set my Ipad to Englsih?
-
HT5639 Are there inherent security risks for installing windows operating systems on a mac?
Just wondering if I use "bootcamp" and install Windows operating system and find out one of the main reasons I switched to a Mac is because of security issues. I also need to know if I can operate the Mac version of "Microsoft Office" without install
-
HT5012 Why do I have a onavo profile on my iPhone 3GS issued by go daddy?
I just saw I have a signing certificate in my iPhone 3GS general profile tab. What is this