LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   why my java code for networking is not working??? (http://www.linuxquestions.org/questions/linux-networking-3/why-my-java-code-for-networking-is-not-working-685982/)

phase_ram 11-25-2008 09:15 AM

why my java code for networking is not working???
 
I have been working with fedora 8 and java 1.6 with lksctp 1.0.9. I tried to run the program in various ways finally the following error occur:

[root@localhost JavaSCTP-0-5-7-src]# java SCTPTest
Exception in thread "main" java.net.SocketException: setsockopt() failed, errno=22
at dk.i1.sctp.SCTPSocket.subscribeEvents(Native Method)
at dk.i1.sctp.SCTPSocket.subscribeEvents(SCTPSocket.java:86)
at SCTPTest.main(SCTPTest.java:20)

How do i get rid of this problem. Please help me.


Regards

krock923 11-25-2008 04:19 PM

Can you post the code?

phase_ram 11-26-2008 03:56 AM

Quote:

Originally Posted by krock923 (Post 3354222)
Can you post the code?

This is the code for the program:
//Simple test program for OneToMany-style sockets*/
import dk.i1.sctp.*;
import java.net.*;
import java.util.*;
import java.net.*;

class SCTPTest {
public static final void main(String[] argv) throws Exception {
OneToManySCTPSocket s = new OneToManySCTPSocket();
if(true) {
sctp_initmsg im = new sctp_initmsg();
im.sinit_num_ostreams = 4;
im.sinit_max_instreams = 7;
s.setInitMsg(im);
}
s.bind(4000);
sctp_event_subscribe ses = new sctp_event_subscribe();
ses.sctp_data_io_event = true;
ses.sctp_association_event = true;
s.subscribeEvents(ses);
s.listen();
Collection<InetAddress> col = s.getLocalInetAddresses();
System.out.println("Server is listening on:");
for(InetAddress ia : col)
System.out.println(ia.toString());


OneToOneSCTPSocket c = new OneToOneSCTPSocket();
if(true) {
sctp_initmsg im = new sctp_initmsg();
im.sinit_num_ostreams = 3;
im.sinit_max_instreams = 2;
c.setInitMsg(im);
}
c.bind();
c.connect(InetAddress.getByName("localhost"),4000);

//grab notification
System.out.println("Doing receive() on server socket");
SCTPChunk chunk = s.receive();
assert ((SCTPNotificationAssociationChangeCommUp)chunk)!=null;
AssociationId client_assoc_id = ((SCTPNotificationAssociationChangeCommUp)chunk).sac_assoc_id;
System.out.println("Got SCTPNotificationAssociationChangeCommUp");
System.out.println("client_assoc_id = " + client_assoc_id.toString());
System.out.println("sac_outbound_streams = " + ((SCTPNotificationAssociationChangeCommUp)chunk).sac_outbound_streams);
System.out.println("sac_inbound_streams = " + ((SCTPNotificationAssociationChangeCommUp)chunk).sac_inbound_streams);

col = s.getPeerInetAddresses(client_assoc_id);
System.out.println("Client is reachable via on port "+s.getPeerInetPort(client_assoc_id)+":");
for(InetAddress ia : col)
System.out.println(ia.toString());

col = s.getLocalInetAddresses(client_assoc_id);
System.out.println("...which can reach us via:");
for(InetAddress ia : col)
System.out.println(ia.toString());

System.out.println("Sending 1000 messages Server->Client");
s.setSctpNoDelay(true); //needed because we do not do request-reply
for(int r=0; r<1000; r++) {
//send a chunk from server to client
SCTPData data = new SCTPData("Hello world".getBytes());
data.sndrcvinfo.sinfo_assoc_id = client_assoc_id;
s.send(data);
chunk = c.receive();
assert ((SCTPData)chunk)!=null;
assert (new String(((SCTPData)chunk).getData())).equals("Hello world");
}
System.out.println("Sending 1000 messages Client->Server");
c.setSctpNoDelay(true); //needed because we do not do request-reply
for(int r=0; r<1000; r++) {
SCTPData data = new SCTPData("Hello to you".getBytes());
c.send(data);
chunk = s.receive();
assert ((SCTPData)chunk)!=null;
assert (new String(((SCTPData)chunk).getData())).equals("Hello to you");
assert (((SCTPData)chunk).sndrcvinfo.sinfo_assoc_id.equals(client_assoc_id));
}
System.out.println("Done. Closing client socket");

c.close();

//grab notification
chunk = s.receive();
assert ((SCTPNotificationAssociationChangeCommLost)chunk)!=null;
assert client_assoc_id == ((SCTPNotificationAssociationChangeCommLost)chunk).sac_assoc_id;

s.close();
}
}





And the error has been arised from this function:
which is located at dk/i1/sctp/SCTPSocket.java
which is as follows:

...
...
...
public void subscribeEvents(sctp_event_subscribe ses) throws SocketException {
subscribeEvents(ses.sctp_data_io_event,
ses.sctp_association_event,
ses.sctp_address_event,
ses.sctp_send_failure_event,
ses.sctp_peer_error_event,
ses.sctp_shutdown_event,
ses.sctp_partial_delivery_event,
ses.sctp_adaptation_layer_event
);
}
private native void subscribeEvents(boolean sctp_data_io_event,
boolean sctp_association_event,
boolean sctp_address_event,
boolean sctp_send_failure_event,
boolean sctp_peer_error_event,
boolean sctp_shutdown_event,
boolean sctp_partial_delivery_event,
boolean sctp_adaptation_layer_event
) throws SocketException;
....
....


....
This is only the part of the program.
If u want the complete program than i could provide u.

Regards


All times are GMT -5. The time now is 03:20 AM.