LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 01-12-2012, 03:28 AM   #1
neethu
LQ Newbie
 
Registered: Jan 2012
Posts: 2

Rep: Reputation: Disabled
problem in image,pdf,.iso file transfer from java client to c++ server (2 machine)


i am trying to send all kind of files from java client to c++ server. all kind of text files are transferred successfully. but when it comes to pdf,image,.iso files, it produces errors like pdf load error, cannot open image, not in .iso format . below i am attaching the c++ server code and java client code.please help me to rectify it.

client1.java
import java.net.*;
import java.io.*;

class client1{
public static void main (String[] args){

DataInputStream input;
String str;
BufferedInputStream bis;
BufferedOutputStream bos;
int in;
byte[] byteArray;

try{
Socket client = new Socket(args[0],Integer.parseInt(args[1]));
System.out.println("enter file");
DataInputStream din1=new DataInputStream(System.in);
str=din1.readLine();
bis = new BufferedInputStream(new FileInputStream(str));
bos = new BufferedOutputStream(client.getOutputStream());
byteArray = new byte[1024];
while ((in = bis.read(byteArray)) != -1){
bos.write(byteArray,0,in);
Thread.sleep(4000);
System.out.println(byteArray);
bos.flush();
}

System.out.println("send successfully");
}
catch ( Exception e ) { }
}}

server1.cpp
#include <iostream>
#include <fstream>
#include <string.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<stdlib.h>
#include<arpa/inet.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdio.h>

using namespace std;

int main()
{

int create_socket,new_socket,fd,m,l;
socklen_t addrlen;char msg[1024];
struct sockaddr_in address;
if ((create_socket = socket(AF_INET,SOCK_STREAM,0)) > 0)
cout<<"The socket was created\n";
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;//INADDR_ANY;inet_addr("localhost");
address.sin_port = htons(1238);
cout<<"\nworking";

if (bind(create_socket,(struct sockaddr *)&address,sizeof(address)) == 0)
cout<<"Binding Socket\n";

listen(create_socket,3);
addrlen = sizeof(struct sockaddr_in);

cout<<"*************************\n";
new_socket = accept(create_socket,(struct sockaddr *)&address,&addrlen);
cout<<"*************************\n";

if (new_socket > 0)
{
char buf[1024];int ch;
cout<<"The Client "<<inet_ntoa(address.sin_addr)<<" is Connected...\n";//inet_ntoa(address.sin_addr));

FILE *fp;
fp=fopen("ren.txt","w");
char message[1024],message1[1024];

ssize_t bytes,byte;
bytes=1;
{

while(bytes!=0)
{

bytes=recvfrom(new_socket,&message, 1024, 0, (struct sockaddr *)&address, &addrlen);
cout<<"hai";
cout<<message;
printf("msg from %s:%d (%d bytes)\n", inet_ntoa(address.sin_addr),ntohs(address.sin_port), bytes);
//outputFile.write(message,sizeof(message));
fwrite(message,1,strlen(message),fp );
memset(message,0x0,sizeof(message));

}
outputFile.close();
fclose(fp);
}


}

close(new_socket);
return close(create_socket);

}
 
Old 01-12-2012, 12:27 PM   #2
MartinStrec
Member
 
Registered: Jan 2012
Location: Czech
Distribution: Fedora, RHEL, Ubuntu, Mint
Posts: 110

Rep: Reputation: 14
Hi,

I'm not sure, if you choose correct forum.

Even, what is the exact error message of Java (post the error example of whole stack trace you get on screen).

You java code loks well, even I miss something that could discover the error message and the line.
 
  


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
Server back up as an Image or .iso file mohanan.sandeep Linux - Server 1 03-03-2011 07:26 AM
Problem Installing fedora11 (iso image) through guest OS machine..... prashni0 Linux - Virtualization and Cloud 1 12-16-2009 10:58 AM
[SOLVED] Problem Installing fedora11 (iso image) through guest OS machine..... prashni0 Linux - Newbie 1 12-16-2009 10:08 AM
[most secure, open source, client/server file transfer program] Synesthesia Linux - Software 5 11-28-2005 08:20 PM

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

All times are GMT -5. The time now is 05:43 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