Help in socket programming

Actually my client and server ,both are running on same m/c.
client code is
Socket s1;
try{
s1 = new Socket("localhost",5678);
catch(Exception e){}
Server Code is
ServerSocket serverSocket = new ServerSocket(port);
while(true) {
     Socket socket = serverSocket.accept();
     InetAddress inetAddress = socket.getInetAddress();
     new Thread(new SocketNode(socket)).start();
where constructor for SocketNode is like this :-
public
SocketNode(Socket socket) {
this.socket = socket;
try {
ois = new ObjectInputStream(socket.getInputStream());
catch(Exception e) {
cat.error("Could not open ObjectInputStream to "+socket, e);
It throws exception in opening object input stream.
Could anybody suggest the possible reasons for it.
error is something like this :-
ERROR [main] Logger.SocketNode (<init>:35) - Could not open ObjectInputStream to Socket[addr=/127.0.0.1,port=1800,localport=5678]
java.net.SocketException: Connection reset by peer: JVM_recv in socket input stream read
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.ObjectInputStream$PeekInputStream.read(Unknown Source)
at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
at Logger.SocketNode.<init>(SocketNode.java:32)
at Logger.SocketServer.main(SocketServer.java:40)
I will be really thankful, if anybody can help in this regards

Hi Neetika,
Your error is telling that
your client program has
teminated before server
could create an ObjectInput
Stream. So, for this you KEEP
your client program
alive for some time( So that
socket object in client side
is not swapped out by Garbage
collector ).
and then you will not get above error.
cheers!

Similar Messages

  • 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.

  • Urgent Help in Socket Programming

    Hello Friends
    I have created a ChatServerApp.java and ChatClient.java as applet files. If i try to execute the chat using appletviewer, the chat module works fine. But when i embed in IE, the chat module shows me error. the error i have given below:
    java.security.AccessControlException: access denied (java.net.SocketPermission 203.101.33.160 resolve)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at ChatServer.CreateServer(ChatServerApp.java:123)
         at ChatServerApp$1.mouseReleased(ChatServerApp.java:36)
         at java.awt.Component.processMouseEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Button.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)java.lang.NullPointerException
         at ChatServer.listenServer(ChatServerApp.java:138)
         at ChatServer.run(ChatServerApp.java:106)
         at java.lang.Thread.run(Unknown Source)
    Can any one please help me to sort out this problem
    Thanks
    S.Srivignesh ([email protected])

    The browser limits the operations you can perform based on the security settings. You need to sign the jar and allow socket connections.

  • Help in Socket Programing Plz

    Hi everyBody!!!
    I m writing a client/server program in which client requests to the server to get the contents of the directory of the server computer (path of the directory is specified by client).
    Server gets the contents fo the director by using the listFile() method and writes that contents onto the socket.
    but the problem is:
    how i can the read that contents from client side? server writes an array of type File onto the socket by using writeObject() method. And client definately will use readObject() method. but how i can read an array of type File from the client side???

    You gave the answer yourself: The Server may write the ARRAY of Files using write Objects and the Client will use readObject. Arrays are Objects too, so do not loop but just write:
    On server Side
    File [] allFiles = getThemFromSomewhere();
    ObjectOutputStream oout = ...;
    oout.writeObject(allFiles); // no loop here!
    ...On client side:
    ObjectInputStream oin = ...;
    File [] allFiles = (File[])oin.readObject()
    ...Well I don't really understand the way you want to do this, because the Files descriptions will be System dependent (and for FileTransfer FTP was created), so this will only make sense when you do interprocess communication on the same system. What do you want to achieve?

  • Need help regarding socket programming

    hi
    i have three machines "W", "D" and "K" on "W" and "D"
    i have server programs which listens to port 9999
    on "D" and "K" i am running client programs which connects to these servers (from "K" either to "W" or to "D" whichever is available and from "D" to "W")
    can this situation ever lead to a BindException

    ... have three machines "W", "D" and "K" on "W" and "D"Huh? Your explaination doesn't make it clear to me.
    Maybe you meant that you have three 'processes' on two different machines?
    What kind of socket are you using - TCP or UDP?
    Typically a bind exception occurs when the socket is already in use. This can occur if you kill a process and bring it up again. Or if two TCP socket servers on the same box try to start up (one of them will fail to grab the socket.)

  • SOCKET PROGRAMMING  HELP NEEDED!!!!

    hi,
    I got an idea of establishing socket connection with all clients from SERVER through the windows command
    called (arp -a). when we type the stated command on dosprompt in server, it gives the list of current system's
    ipaddress.....switched on. SO i can establish socket connections in a for loop where i can take the following ipaddress from output listed from command.
    i've written the code to call the command in JAVA.
    i write the dosprompt output in a file named list1.txt
    import java.util.*;
    import java.io.*;
    import java.io.File;
    public class RunCommand
    public static String[] runCommand(String cmd) throws IOException
    ArrayList list = new ArrayList();
    Process proc = Runtime.getRuntime().exec(cmd);
    InputStream istr = proc.getInputStream();
    BufferedReader br = new BufferedReader(new InputStreamReader(istr));
    String str;
    while ((str = br.readLine()) != null)
    list.add(str);
    try
    proc.waitFor();
    }catch (InterruptedException e)
    System.err.println("process was interrupted");
    // check its exit value
    if (proc.exitValue() != 0)
    System.err.println("exit value was non-zero");
    // close stream
    br.close();
    // return list of strings to caller
    return (String[])list.toArray(new String[0]);
    public static void main(String[] args) throws Exception
    try
    FileWriter f1=new FileWriter("list1.txt");
    String[] s = runCommand("arp -a");
    for (int i = 0; i< s.length; i++)
    f1.write(s);
    System.out.println(s[i]);
    f1.close();
    }catch (Exception ex) { System.out.println(ex);}
    SAMPLE OUTPUT:
    Interface: 172.16.3.1 on Interface 0x1000003
    Internet Address Physical Address Type
    172.16.3.4 00-00-e2-13-a9-e8 dynamic
    172.16.3.6 00-00-e2-13-aa-0f dynamic
    172.16.3.10 00-00-e2-13-ab-bb dynamic
    172.16.3.12 00-00-e2-13-ab-93 dynamic
    172.16.3.16 00-00-e2-13-37-b8 dynamic
    172.16.3.17 00-00-e2-13-37-19 dynamic
    172.16.3.18 00-00-e2-13-37-1d dynamic
    172.16.3.19 00-00-e2-13-38-98 dynamic
    172.16.3.22 00-00-e2-13-37-54 dynamic
    172.16.3.23 00-00-e2-13-39-02 dynamic
    172.16.3.24 00-00-e2-13-39-0f dynamic
    172.16.3.26 00-00-e2-13-37-a5 dynamic
    172.16.3.27 00-00-e2-13-37-0b dynamic
    172.16.3.28 00-00-e2-13-37-12 dynamic
    172.16.3.29 00-00-e2-13-39-15 dynamic
    172.16.3.30 00-00-e2-13-38-af dynamic
    172.16.3.31 00-00-e2-13-37-fe dynamic
    172.16.3.32 00-00-e2-13-38-ff dynamic
    172.16.3.34 00-00-e2-13-ab-c8 dynamic
    172.16.3.37 00-00-e2-13-ab-67 dynamic
    172.16.3.42 00-00-e2-13-ab-19 dynamic
    PLS HELP ME OUT IN GETTING ONLY THE IPADDRESS IN FOR LOOP IN SERVER SOCKET PROGRAM TO INVOKE ALL CLIENT'S PROGRAM IN NETWORK.
    PLS HELP ME!!!!!!!
    ATTACH THE CODE!!!!!!!!!!!!

    Connecting to a client presumes that the client is waiting for a connection.
    If that is the case I would suggest looking a java.net.Socket.

  • Help needed with swings for socket Programming

    Im working on a Project for my MScIT on Distributed Computing...which involves socket programming(UDP)....im working on some algorithms like Token Ring, Message Passing interface, Byzantine, Clock Syncronisation...i hav almost finished working on these algorithms...but now i wanna give a good look to my programs..using swings but im very new to swings...so can anyone help me with some examples involving swings with socket programming...any reference...any help would be appreciated...please help im running out of time..
    thanking u in advance
    anDy

    hi im Anand(AnDY),
    i hav lost my AnDY account..plz reply to this topic keeping me in mind :p

  • Help on Server Socket Programming??????

    hello Friends,
    I need your help on following:
    I am the only person working on this project and the company wants me to prepare a infrastructure of this project and I should also give a demo of this project to my seniors. I will breif you up with my project:
    1. There is this gif image of distillation column. i will be publishing it using JApplet or Applet.
    2. This Image must be seen on internet.
    3. On the circle of these Image the user will click(In all there are five circles, called as controllers)and a dialog box should open thru which user will input the float values(I am using the JOptionPane class to open this dialog box).
    4. The inputed values will the be given to the C program which is the simulator for distillation column.
    5. The C program will generate the output through iterations(Code entirely in C), the output of each program will then be poped up to over the image beside the respective controlled or under the respective controller but definetely over the same gif file.
    6. The number of iteration will depend on how fast the C program converges the inputer parameters. And each output must be show over the gif image and when the final iteration value will appear it should remain on the image until some new value is inputted by the user again by clicking on any of the circle.
    The proposed theory to do this project accoding to me is as follows:
    1. Since each value must be thrown to the user. I beleive this is a real time project. So I decided to use Client Server Networking technology provided by java.
    2. Then I figured out that in this project there should be 2 clients One is the GUI which is the Image screen to receive the input from the user and to show the output to the user. Second client is a java program sitting behind the server which will receive this input data from user and it will have an NATIVE method through which all this input will be given to the C simulator program.
    3. The middle bridge between these two clients will be a server. Which will just pass the data to and fro from both the clients.
    3. The C program will perform iterations using these input values from second client. This C program will then give each iterations output to the Java program using JNI technology. This second client then sends this output value to the GUI clients through server.
    Well another very important thing, I am inexperience in the field of software so I had to do a lot of R&D and this is what I found out. Frankly I am really not sure whether this is the right path to approach to this project or there is some other correct and realistic way than this? Well friends i would certainly request you if you can suggest some other simple or rather correct path or else if this is the right path then would you please suggest me the possible hiches or perticular points where I should concentrate more.
    Well i am eagerly waiting for your reply.

    Since you are publishing your results on the net , it will be a better idea to use JSP?Servlet/Beans architecture instead of swing
    I will propose a architecture as follows:
    Client : Standard Browsers, IE and NS
    Middle Tier: Java Webserver/Application Server
    This will depend on your budget. If u have a fat allowance go for weblogic/websphere . If u are operationg on shoe string budget try for apache , etc
    In the server tier code your application in the follwing architecture
    JSP for presentation: Distillation towers picture, input boxes .. etc
    Servlets for business logic invocation and routing requests: Your JSP submits input values to servlets, which does the processing using Java Bean Components. Since you have a lot of Logic written in C I would suggest to encapsulate these in JavaBean components using JNI technology and reuse the code.
    After processing the servlet again forwards the response to another JSP for output
    Advantages:
    1.Your clients can be thin as most of the processing is done at the server
    2. Thread Management is taken care of by your webserver, which otherwise would be a headache
    3. Writing this through low level socket programming will be much more difficult as you will write your own protocol for communication this will be error prone and not scalable
    If you still decide to go for traditional client server programming using swing, use RMI for communication as I insist that socket programming is very very cumbersome...using your own protocols
    hope this helps
    Shubhrajit

  • 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 PM

    Hi,
    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
    Sulfikkar

    There 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 .

  • [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.

  • About Socket program in ABAP

    Hi all,
    Can I do Socket program in ABAP?
    I know nothing about that,Can anyone help?
    Thanks very much.
    Pole

    Within ABAP you have access to OLE objects - take a look at ABAB stement SET PROPERTY.
    In our production we have some scale weights connected to a PC. On the PC an external vendor has created an OLE obejct that can retur te current state and weight of the scale weight directly into a SAP screen.
    I guess if you can write an OLE obejct that can handle it - it is possible.

Maybe you are looking for