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;
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)
Why C++ and not just plain C? Is the client program to run on UNIX or or on Windows? What happens when the program fails to complete the transfer? How soon is the homework assignment due?
The reason why i have chosen C++ is because the assignment is a video mail program , and tha client must communicate with the Gstreamer.Of course the programm will run on Linux!!!!!!!!!!!!
Now i have written new code for the Server
public BufferedOutputStream recv_data() throws IOException
{
BufferedOutputStream f = null;
long tlen = 0;
byte[] buf = new byte[32768];
int[] val = new int[1];
What i am trying to do right now is to right the C++ code , but i do not if C++ has something like BufferedOutputStream .Do not worry about the assignment due :-)
You'd need to use exactly the data class gstreamer used anyhow, so this' more a question about gstreamer than C++. C code is still perfectly valid inside C++, by the way, so you can still use the normal socket() calls and all that. What I would do is first write a pure C program that does nothing but connect to and read from the socket, then see how I could fit bits of it into gstreamer rather than trying to build the whole thing at once, that's just an invitation for headaches.
I'm not sure you need to write anything, though. gstreamer comes with the ability to read from TCP sockets. Unless gstreamer needs a special data format on the socket I don't see why it couldn't connect to your Java program.
Last edited by Corona688; 01-07-2009 at 03:22 PM..
My question is how to create the function that sends a file in C++/C . Because Java has a Class like : BufferedOutputStream , but C hasn't.
When i send a string for example over the socket i use the function : send(new_fd, (char *) str, strlen(str), 0) but i do not know what to do when i have a file , how should i transform the "send" function?
The gstreamer part is irrelevant , do not worry about that, just focus on the client/server .
Okay. UNIX uses the open(), read() and write() calls to deal with files, and the recv() and send() calls to deal with sockets. It uses the socket() and bind() calls to create a server socket and give it an address, or the socket() and connect() calls to make and connect a client socket to something. close() works for both files and sockets. There's lots and lots of examples for these all over the internet, and probably manpages on your system, try 'man 2 socket'.
which will work on UNIX systems in general. You mention Linux in particular, which has an especially easy and efficient way:
Note that sendfile is special, it can only read from files and can only send to sockets.
See 'man 2 send', 'man 2 read', etc. for details on these functions like what include files they need.
Last edited by Corona688; 01-07-2009 at 04:00 PM..
If you need to work with a special C++ class or to write C++ code in general, this is probably the wrong site for it. As I understand it (don't let the moderator status fool you, I'm still somewhat new here), the forum deals with high level programming questions that are related and/or specific to UNIX. Beyond what Corona posted above, I'm not sure you can get squeeze much more out of us
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)
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)
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)
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)
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)
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)
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)
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)
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)