Sponsored Content
Full Discussion: File Transfer over Sockets
Top Forums Programming File Transfer over Sockets Post 302273728 by mcnikolas on Monday 5th of January 2009 03:46:28 PM
Old 01-05-2009
File Transfer over Sockets

Hello there !!!!!!!!! I got some problems trying to transfer a file through sockets.

The Server must be in Java and the Client in C++

I came up with this code for the server :

BufferedInputStream input;
BufferedOutputStream output;
public void send_data() throws IOException
{
File transfer = new File("tux.png");
InputStream in = new FileInputStream(transfer);


byte[] buff = new byte[sock.getSendBufferSize()];
int bytesRead = 0;

System.out.println(transfer.length()+ " bytes");

while((bytesRead = in.read(buff))>0)
{
output.write(buff,0,bytesRead);
}
in.close();
}
public void recv_data() throws IOException
{
InputStream input = sock.getInputStream();
FileOutputStream wr = new FileOutputStream(new File("Test"));
byte[] outBuffer = new byte[sock.getReceiveBufferSize()];
int bytesReceived = 0;

while((bytesReceived = input.read(outBuffer))>0)
{
wr.write(outBuffer,0,bytesReceived);
}
wr.close();


}



But i can not do the client side in C++. Can anybody give an example??
If the code a give you is very confusing , it would be OK to give a very simple example of how to send/recv a file from/to client(C++)/server/(Java)


Thank you in advance.
 

10 More Discussions You Might Find Interesting

1. Programming

Sockets and File descriptors

I am in a Systems programming class this semester, and our current project is to write a program utilizing sockets and fork. For the project, I decided to make my own instant messaging program. I have the code completed, but I have a problem that keeps old clients from communicating with new... (3 Replies)
Discussion started by: gstlouis
3 Replies

2. Shell Programming and Scripting

file transfer

hi all how do i copy a file from one server to another thanks bkan77 (4 Replies)
Discussion started by: bkan77
4 Replies

3. UNIX for Dummies Questions & Answers

Transfer the file

Dear all, Can anybody let me know how to automate a file transfer process to a remote m/c thru SFTP , automate means it will not prmpt for password. how i am going to achive this....and what all methods are available or tools are available ???? (2 Replies)
Discussion started by: manas_ranjan
2 Replies

4. Shell Programming and Scripting

File transfer

Hi All, it might not be an sound question, i have two server like A and B.. i want to transfer file from B to A ..here i have some questions.. 1) do we need to create private and public key to connect..and transferring files...from B to A..? 2) i tried with scp options like... (2 Replies)
Discussion started by: Shahul
2 Replies

5. Programming

Problem in file transfer using sockets

Hai Friends I am writing a c program to transfer files from one system to another using TCP/IP socket programming.. My Recieve Program #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> extern int errno; extern char *sys_erlist; void... (2 Replies)
Discussion started by: collins
2 Replies

6. Programming

Sending large file through sockets

Hello, I am trying to send a file (1 MB) through sockets and for some reason I am getting segmentation fault message and receiving in the server an incomplete file. The current file is about 3 pages long and need to send it from the client to the server. I've tried malloc with free(), I am now... (8 Replies)
Discussion started by: sfcddm1
8 Replies

7. Programming

File transfer in C

HI Can anyone provide me with codes for file transfer server to client or vice versa? Also please explain how to compile those programs in ubuntu terminal as i am totally new to socket programming. Thanks (0 Replies)
Discussion started by: mayhemtrigger
0 Replies

8. Shell Programming and Scripting

Avoiding file overwrite during file transfer using scp

Hi, I have written a small script to transfer a file from one unix server to other using scp command which is working fine. As I know with scp, if any file with the same name is already present on destination server, it would get overwritten without any notification to user. Could anyone help me... (14 Replies)
Discussion started by: dsa
14 Replies

9. Shell Programming and Scripting

File transfer script

Hi, I need a shell script to transfer a file from one server(unix box) to another server(windows box). I have the details of the source and destination Ip's. source path : /home/UNIX/server filename:abc.txt Destination folder: D:/UNIX/test I am using AIX server. Type of shell :... (1 Reply)
Discussion started by: NareshN
1 Replies

10. UNIX for Advanced & Expert Users

File transfer

When using FTP to transfer a file from IBM iSeries family of servers client to a non IBM Iseries family server, files might have characters appear in the wrong format Eg | in Iseries and while transferring fro Iseries system to Linux , but instead of | it is showing as ?. Please advise (3 Replies)
Discussion started by: sudhainit
3 Replies
CLIENTLIB(3)						     Library Functions Manual						      CLIENTLIB(3)

NAME
clientlib - NNTP clientlib part of InterNetNews library SYNOPSIS
extern FILE *ser_rd_fp; extern FILE *ser_wr_fp; extern char ser_line[]; char * getserverbyfile(file) char *file; int server_init(host) char *host; int handle_server_response(response, host) int reponse; char *host; void put_server(text) char *text; int get_server(buff, buffsize) char *buff; int buffsize; void close_server() DESCRIPTION
The routines described in this manual page are part of the InterNetNews library, libinn(3). They are replacements for the ``clientlib'' part of the NNTP distribution, and are intended to be used in building programs like rrn. Getserverbyfile calls GetConfigValue to get the name of the local NNTP server. It returns a pointer to static space. The file parameter is ignored. Server_init opens a connect to the NNTP server at the specified host. It returns the server's response code or -1 on error. If a connec- tion was made, then ser_rd_fp and ser_wr_fp can be used to read from and write to the server, respectively, and ser_line will contain the server's response. Ser_line can also be used in other routines. Handle_server_response decodes the response, which comes from the server on host. If the client is authorized, it returns 0. A client that is only allowed to read is authorized, but handle_server_response will print a message on the standard output. If the client is not authorized to talk to the server, then a message is printed and the routine returns -1. Put_server sends the text in buff to the server, adding the necessary NNTP line terminators, and flushing the I/O buffer. Get_server reads a line of text from the server into buff, reading at most buffsize characters. Any trailing terminators are stripped off. Get_server returns -1 on error. Close_server sends a ``quit'' command to the server and closes the connection. HISTORY
Written by Rich $alz <rsalz@uunet.uu.net> for InterNetNews. This is revision 42, dated 1997-08-04. SEE ALSO
libinn(3). CLIENTLIB(3)
All times are GMT -4. The time now is 07:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy