ServerSocket Problem

import java.io.*;

import java.net.*;

import java.awt.*;

import javax.swing.*;

public class Server extends JFrame {

/**

*

*/

private static final long serialVersionUID = 1L;

private JTextArea display;

private JScrollPane sp;

public Server() {

super("Server");

display = new JTextArea();

sp = new JScrollPane(display);

getContentPane().add(sp, BorderLayout.CENTER);

setSize(350, 250);

setVisible(true);

}

public void runServer() {

ServerSocket server=null;

Socket connection;

DataOutputStream output;

DataInputStream input;

String line;

int counter = 1;

byte[] buffer = new byte[50] ;

int count = 0,total = 0;

try {

// Adim 1: Bir ServerSocket olustur.

server = new ServerSocket(6000,100);

while (true) {

// Adim 2: Bir baglanti bekle........

display.append("Server is waiting for a client connection...\n");

connection = server.accept();

display.append("Connection " + counter + " received from: " +

connection.getInetAddress().getHostName());

// Adim 3: Giris ve cikis streamleri olustur

input = new DataInputStream(connection.getInputStream());

output = new DataOutputStream(connection.getOutputStream());

// Adim 4: Istemci sunucu islemleri

try {

String str = "ok";

output.write(str.getBytes());

while (total < 50 ) {

count = input.read(buffer,total,50 - total);

if (count < 0 ) {

break;

}

total += count;

}

String reply = new String(buffer,0 ,total);

display.append(reply);

//display.append("Client message : " + input.read());

} catch (IOException e ) {

System.err.println(e);

System.exit(0);

}

// Adim 5: Baglantiyi kapat.

display.append("\nTransmission complete. " + "Closing socket.\n\n");

connection.close();

++counter;

// Adim 6: 2. Adima geri don.

}

}

catch (IOException e) {

e.printStackTrace();

}

}

public static void main(String[] args) {

Server s = new Server();

s.setDefaultCloseOperation(EXIT_ON_CLOSE);

s.runServer();

}

}

this my code and in this line

server = new ServerSocket(6000,100);

there is a error.

java.net.SocketException: Network is down: listen failed

at java.net.PlainSocketImpl.socketListen(Native Method)

at java.net.PlainSocketImpl.listen(Unknown Source)

at java.net.ServerSocket.bind(Unknown Source)

at java.net.ServerSocket.<init>(Unknown Source)

at java.net.ServerSocket.<init>(Unknown Source)

at Server.runServer(Server.java:38)

at Server.main(Server.java:98)

and error message. can anyone help me!!

[2893 byte] By [umitkavala@gmail.coma] at [2007-10-3 8:09:28]
# 1
As the message says, 'Network is down'.
ejpa at 2007-7-15 3:13:43 > top of Java-index,Archived Forums,Socket Programming...
# 2
but why? i can compile this code another computer without any problem
umitkavala@gmail.coma at 2007-7-15 3:13:43 > top of Java-index,Archived Forums,Socket Programming...
# 3
Where you can compile it is irrelevant. This is a run-time exception and it means that the network attached to the computer you ran it on is down. This is a problem with the computer or your network, not with the Java code.
ejpa at 2007-7-15 3:13:43 > top of Java-index,Archived Forums,Socket Programming...
# 4

If a listen failed, then there is an issue with the MAC/LLC layer signaling (CSMA), or software, as listening to the media is local to the host, not to the network (in CSMA networks).

Therefore, it is more likely software.

You are right, and it appears the OP does not understand that it is a run-time exception.

I had a guy tonight asking why a URL didn't work, when he tried to pass a String (s1) like this "s1" as an argument to the URL. We need something more exciting then these questions.

watertownjordana at 2007-7-15 3:13:43 > top of Java-index,Archived Forums,Socket Programming...
# 5
It is more likely that he has a dialup connection which isn't up so the entire TCP stack isn't up.
ejpa at 2007-7-15 3:13:44 > top of Java-index,Archived Forums,Socket Programming...
# 6
Sounds right to me, though I would think a different error would occur. You're correct.
watertownjordana at 2007-7-15 3:13:44 > top of Java-index,Archived Forums,Socket Programming...