LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 11-25-2008, 09:15 AM   #1
phase_ram
LQ Newbie
 
Registered: Oct 2008
Posts: 20

Rep: Reputation: 0
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
 
Old 11-25-2008, 04:19 PM   #2
krock923
Member
 
Registered: Jul 2004
Posts: 171

Rep: Reputation: 30
Can you post the code?
 
Old 11-26-2008, 03:56 AM   #3
phase_ram
LQ Newbie
 
Registered: Oct 2008
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by krock923 View Post
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SED - minor changes work - Larger doesn't (working and non working code included) Nimoy Programming 17 09-22-2007 04:34 PM
Networking Code Problem Mercurius Programming 2 05-17-2006 01:15 AM
Java/Firefox java plugin not working with HP Webjetadmin iamskykid Linux - Software 2 03-02-2006 02:38 PM
Java - networking - why working in Lin and not Win? rylan76 Programming 0 09-02-2005 03:55 AM
Web start java not working (java works fine) powadha Debian 5 06-05-2004 12:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration