java.net.ConnectException: Connection refused in TCP socket? -
i have created program send file client server when running file in localhost works , can send file when sending file pc pc shows "java.net.connectexception: connection refused".
port number @ both side same , firewall off. port listening when client request connect server socket accepting socket.
thank in advance
code of program :
public class programsocket { public programsocket(serversocket servsock) throws ioexception { system.out.print("server started"); while (true) { final socket sock; try { sock = servsock.accept(); } catch (socketexception e) { break; } new thread(new runnable() { @override public void run() { try { connecttonewclient(sock); } catch (exception e) { e.printstacktrace(); } } }).start(); } system.out.print("server stopped"); } void connecttonewclient(socket sock) throws ioexception, interruptedexception { fileoutputstream fos = new fileoutputstream("c:/abc.txt"); bufferedoutputstream bos = new bufferedoutputstream(fos); int bytesread = is.read(mybytearray, 0, mybytearray.length); bos.write(mybytearray, 0, bytesread); bos.close(); sock.close(); } }
client side :
public string uploadfile(string filepath) throws exception { socket sock = new socket(ip, 24999); // select file file myfile = new file(filepath); // send program file byte[] mybytearray = new byte[(int) myfile.length()]; bufferedinputstream bis = new bufferedinputstream( new fileinputstream(myfile)); outputstream os = sock.getoutputstream(); bis.read(mybytearray, 0, mybytearray.length); os = sock.getoutputstream(); os.write(mybytearray, 0, mybytearray.length); os.flush(); bis.close(); sock.close(); return message; }
omitted code brevity.
Comments
Post a Comment