Click here to Skip to main content
15,914,222 members
Home / Discussions / Java
   

Java

 
QuestionNurse Rostering using Clonal Selection Algorithm Pin
rohaya887-Nov-11 19:58
rohaya887-Nov-11 19:58 
JokeRe: Nurse Rostering using Clonal Selection Algorithm Pin
Gerben Jongerius7-Nov-11 20:30
Gerben Jongerius7-Nov-11 20:30 
AnswerHints Pin
TorstenH.7-Nov-11 21:43
TorstenH.7-Nov-11 21:43 
GeneralRe: Hints Pin
rohaya8810-Nov-11 3:21
rohaya8810-Nov-11 3:21 
AnswerRe: Nurse Rostering using Clonal Selection Algorithm Pin
Richard MacCutchan7-Nov-11 22:44
mveRichard MacCutchan7-Nov-11 22:44 
QuestionCompile-time Annotation Processing [Solved] Pin
Skippums7-Nov-11 16:35
Skippums7-Nov-11 16:35 
AnswerRe: Compile-time Annotation Processing Pin
Skippums15-Nov-11 14:32
Skippums15-Nov-11 14:32 
QuestionTransfer File between client and server with TCP Socket Pin
lolostar7-Nov-11 5:39
lolostar7-Nov-11 5:39 
I need to transfer file between client and server by using tcp socket as this code :

1- sender side ( server ):

Java
spackage sender;

import java.io.*;
import java.net.*;
import javax.swing.*;
import java.util.Scanner;

public class Sender
{
	//declare a ServerSocket
	private static ServerSocket serverSocket;

	public static void main(String[] args)
	{
		System.out.println("Opening port...\n");

		try
		{
	       //create a ServerSocket with a port number 3000
		serverSocket = new ServerSocket(3000);
		}
		catch(IOException ioEx)
		{
		System.out.println("Unable to attach to port!");
		System.exit(1);
		}

		try
		{
               //create a new socket to connect with client and accept the connection 
		Socket link = serverSocket.accept();
		//create ObjectOutputStream that enable us to buffer array of bytes 
		ObjectOutputStream outStream = new   ObjectOutputStream(link.getOutputStream());
		//creat FileInputStream to obtain input bytes from a file
		FileInputStream fileIn = new FileInputStream("image.GIF");
		//get the file length
		long fileLen =  (new File("image.GIF")).length();
		//convert the length to int
		int intFileLen = (int)fileLen;
		//create an array of byte with the file length
		byte[] byteArray = new byte[intFileLen];
		//Read bytes of data from this input stream into an array of bytes
		fileIn.read(byteArray);
		//close this file input stream
		fileIn.close();
		//write the array of byte to the buffer (ObjectOutputStream)
		outStream.writeObject(byteArray);
		}
		catch(IOException e)
		{
		     System.out.println("error...");
		}
	}
}



2- receiver side (Client):
Java
package reciever;

import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

public class Reciever
{
	public static void main(String[] args) throws Exception
	{

		try
		{
		//create a socket with the agreed port
		Socket link = new Socket("localhost",3000);
		//create ObjectOutputStream that enable us to buffer array of bytes 
		ObjectInputStream inStream = new ObjectInputStream(link.getInputStream());
		//create a array of bytes with the inputStream length (length of recieved array)
		byte[] byteArray = (byte[])inStream.readObject();
		//output stream for writing data to a File
	      	FileOutputStream outStream = new FileOutputStream("image.GIF");
	      	//Write byteArray to this file output stream
			                                                           outStream.write(byteArray);			
		//close the connection
		link.close();
		}
		catch(IOException e)
		{
			System.out.println("error...");
		}
	}
}



and the image.GIF file found at the sender side but this code make error , I need solution for this problem as soon as , please .
AnswerRe: Transfer File between client and server with TCP Socket Pin
Luc Pattyn7-Nov-11 5:58
sitebuilderLuc Pattyn7-Nov-11 5:58 
GeneralRe: Transfer File between client and server with TCP Socket Pin
David Skelly7-Nov-11 6:17
David Skelly7-Nov-11 6:17 
GeneralRe: Transfer File between client and server with TCP Socket Pin
Nagy Vilmos7-Nov-11 7:43
professionalNagy Vilmos7-Nov-11 7:43 
GeneralRe: Transfer File between client and server with TCP Socket Pin
lolostar7-Nov-11 6:26
lolostar7-Nov-11 6:26 
GeneralRe: Transfer File between client and server with TCP Socket Pin
Luc Pattyn7-Nov-11 6:38
sitebuilderLuc Pattyn7-Nov-11 6:38 
GeneralRe: Transfer File between client and server with TCP Socket Pin
Richard MacCutchan7-Nov-11 7:46
mveRichard MacCutchan7-Nov-11 7:46 
GeneralRe: Transfer File between client and server with TCP Socket Pin
Nagy Vilmos7-Nov-11 7:50
professionalNagy Vilmos7-Nov-11 7:50 
AnswerRe: Transfer File between client and server with TCP Socket Pin
Nagy Vilmos7-Nov-11 7:49
professionalNagy Vilmos7-Nov-11 7:49 
GeneralRe: Transfer File between client and server with TCP Socket Pin
lolostar7-Nov-11 8:28
lolostar7-Nov-11 8:28 
AnswerRe: Transfer File between client and server with TCP Socket Pin
David Skelly7-Nov-11 22:15
David Skelly7-Nov-11 22:15 
AnswerRe: Transfer File between client and server with TCP Socket Pin
anshul.zunke19-Nov-11 3:30
anshul.zunke19-Nov-11 3:30 
QuestionLicensing Java Application?!? Pin
Firo Atrum Ventus6-Nov-11 16:09
Firo Atrum Ventus6-Nov-11 16:09 
AnswerRe: Licensing Java Application?!? Pin
TorstenH.6-Nov-11 19:31
TorstenH.6-Nov-11 19:31 
GeneralRe: Licensing Java Application?!? Pin
Firo Atrum Ventus6-Nov-11 19:43
Firo Atrum Ventus6-Nov-11 19:43 
AnswerRe: Licensing Java Application?!? Pin
Bernhard Hiller6-Nov-11 22:46
Bernhard Hiller6-Nov-11 22:46 
GeneralRe: Licensing Java Application?!? Pin
Firo Atrum Ventus6-Nov-11 23:05
Firo Atrum Ventus6-Nov-11 23:05 
QuestionHow to print restaurant bill directly to printer ? Pin
tannghia6-Nov-11 3:32
tannghia6-Nov-11 3:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.