Programming :: TCP / UDP File Transfer In C Or C++

Oct 27, 2010

I need to create a program that has both a server and a client and can transmit PDF and text files between the two using UDP as the underlying carrier while behaving as if it is TCP. We have successfully created a UDP program that can simply transmit strings, but we are not really sure on how to transform this code to do files. We know that we need to use a buffer of some sort to transmit the file in pieces.

Code:
//dg_cli.c
#include "unp.h"
#include "sys/socket.h"
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
#include "arpa/inet.h"
#include "netdb.h"
#include "sys/file.h"
#include "sys/types.h"

void dg_cli(FILE *fp, int sockfd, const SA *pservaddr, so
{ int n;
char sendline[MAXLINE], recvline[MAXLINE + 1];
while (fgets(sendline, MAXLINE, fp) != NULL) {
sendto(sockfd, sendline, strlen(sendline), 0, pse
n = recvfrom(sockfd, recvline, MAXLINE, 0, NULL,
recvline[n] = 0; /* null terminate */
fputs(recvline, stdout); } }

Code:
//dg_echo.c
#include "unp.h"
#include "sys/socket.h"
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
#include "arpa/inet.h"
#include "netdb.h"
#include "sys/file.h"

void dg_echo(int sockfd, SA *pcliaddr, socklen_t clilen)
{ int n;
socklen_t len;
char mesg[MAXLINE];
for ( ; ; ) {
len = clilen;
n = recvfrom(sockfd, mesg, MAXLINE, 0, pcliaddr, &len);
sendto(sockfd, mesg, n, 0, pcliaddr, len); } }

Code:
//udpcli01.c
#include "unp.h"
#include "sys/socket.h"
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
#include "arpa/inet.h"
#include "netdb.h"
int
main(int argc, char **argv)
{ int sockfd;
struct sockaddr_in servaddr;
if (argc != 2) {
fputs("usage: udpcli <IPaddress>", stderr);
exit(0);
} bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(SERV_PORT);
inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr));
exit(0);
}

Code:
//udpserv01.c
#include "unp.h"
#include "sys/socket.h"
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
#include "arpa/inet.h"
#include "netdb.h"

int
main(int argc, char **argv)
{ int sockfd;
struct sockaddr_in servaddr, cliaddr;
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(SERV_PORT);
bind(sockfd, (SA *) &servaddr, sizeof(servaddr));
dg_echo(sockfd, (SA *) &cliaddr, sizeof(cliaddr));
}

Code:
//unp.h
#include "sys/socket.h"
#include <stdio.h>
#define MAXLINE 4096
/* max text line length */
#define SERV_PORT 9877
#define SA struct sockaddr
void dg_cli(FILE *, int, const SA *, socklen_t);
void dg_echo(int, SA *, socklen_t);

View 1 Replies


ADVERTISEMENT

General :: RSYNC Error .tar.gz 14gb File / Transfer Huge 14 Gb File Over Network,vpn,wan Transfer?

Mar 10, 2010

i am trying to transfer a file from my live linux machine to remote linux machine it is a mail server and single .tar.gz file include all data. but during transfer it stop working. how can i work and trouble shooot the matter. is there any better way then this to transfer huge 14 gb file over network,vpn,wan transfer. the speed is 1mbps,rest of the file it copy it.

rsync -avz --stats bkup_1.tar.gz root@10.1.1.22:/var/opt/bkup

[root@sa1 logs_os_backup]# less remote.log
Wed Mar 10 09:12:01 AST 2010
building file list ... done
bkup_1.tar.gz
deflate on token returned 0 (87164 bytes left)
rsync error: error in rsync protocol data stream (code 12) at token.c(274)
building file list ... done
code....

View 1 Replies View Related

Programming :: UDP File Transfer Error?

Apr 28, 2011

I have an assigment to create UDP file transfer with checksum,but currently i have a problem in transferring the data. The problem is:A.I sent a text file that have approximately 200kb but in the client receive only 100kb... is it fair?B.For text file,I track the result and i found that its okay for the text file. Write counter show 1024 byte every packet i sent. But when i sent mp3 file or pdf file it doenst show like this. For mp3 the data sent every packet i sent is gradually decreased from 1024 byte 1020byte contiounusly.... For pdf data its seems random.

View 6 Replies View Related

General :: Sony PSP File Transfer Inaccurate Transfer Progress?

Jan 1, 2010

Having a bit of a issue with Debian Squeeze and transferring files to the Sony PSP..Hook up PSP to USB port and Debian mounts it..I go to drag a 125 meg mp4 to video folder..Copy windows takes about 10 seconds to transfer it..Exit USB mode and there is no video there. Go back into USB mode and look at video folder on the PSP memory stick and there is no video..It vanished. From another after copy progress closed I right clicked PSP and unmounted it..

It error-ed saying device was busy and could not unmount..Looking at light on PSP i see memory stick is still being written to..i wait for light to stop flashing..About a minute or so..Then am able to unmount it..Go to PSP video and theres the video ready to be watched. Debian isnt accurately showing the copy progress...Its showing complete when it isnt..I have to watch the light on PSP to know when it is truly finished.

View 3 Replies View Related

Programming :: Data Transfer Between Threads?

Dec 14, 2010

In posix multi threading, how to send thread1 local data to thread2...?

View 3 Replies View Related

Programming :: Parallel Data Transfer Using Sockets

Feb 25, 2011

I am doing a project where 2 clients connect to server and communicate (chat) and transfer data one after other using sockets. I have working code for this in C language. Now our main aim is to create a communication link where two clients transfer multiple streams data parallely. To be more precise i want to transfer images files and audio files parallel at same time, so is it possible to send data parallel using one socket connection?

View 3 Replies View Related

Programming :: Transfer C Codes From UNIX To System?

Jun 16, 2010

I got some problems and need your help.

In school, my codes are writeen under UNIX system (Solaris10/SUN), now I need to transfer those codes to Linux (Redhat5). But after I directly copy to Linux, it shows many errors and warnings.

Does anyone know which codes I need to modify to specifily suit for UNIX? I am not familiar with those systems and hope to get your kind help.

View 5 Replies View Related

Programming :: How To Transfer Search Output Between Two Server

May 25, 2011

I want to search for 1 file (say test.txt) on first server and all the output of this search to be greped as per my requirement and then transfered on the second server at the same location where they were on first server.

E.g.
output of search of file (test.txt) >> output.txt
/tmp/test.txt
/home/cpan/test.txt
/opt/cpanel/test.txt

Now I want to grep this output to only related to cpanel,
for f in 'cat output.txt'
echo $f | grep "cpanel"
if [ $? -eq 0 ]
then do scp.
But I am bit confused here, as in how to use scp command here.
scp $f root@second_server:/$f ?

View 3 Replies View Related

Programming :: Shell Script Terminated After FTP Transfer

Dec 28, 2009

I made a shell script with the following piece of code to transfer some files via ftp:

Code:
echo 'before ftp'
ftp -n $FtpHost << EOF
quote USER $FtpUser
quote PASS $FtpPasswd
quote CWD $FtpDir
put $FileNameLog
put $FileNameSqlTarSum
put $FileNameSqlTar
put $FileNameWwwTarSum
put $FileNameTar
quit
EOF

echo 'before rm'
rm $FileNameWwwTar $FileNameWwwTarSum $FileNameSql $FileNameSqlTar $FileNameSqlTarSum $FileNameLog
echo 'after rm'

The problem is that the script ends after the "quit" command in FTP, so code after it won't run, like the remove of temporary files. If I remove this "quit" command, the shell understands I'm still parsing commands to FTP, although being after the EOF. I used this echo commands to check which parts of the script are running.

View 7 Replies View Related

General :: File Transfer Through SSH?

May 25, 2010

I have a linux server and I have SSH Access to it.

How do I transfer my files to my desktop.

View 1 Replies View Related

Fedora :: File Transfer By GUI Over SSH -X

Aug 5, 2011

I have setup ssh between a F15 box and a remote centOS box. I am using ssh -X, then nautilus/gnome-session to open a gui file browser/desktop environment of remote machine. But anything I want to copy from remote machine to local machine by gui, is showing 'path not found' error. CLI work just fine but is it possible to transfer files between remote and local machine by gui over ssh?

View 3 Replies View Related

General :: File Transfer By Using SCP?

Feb 14, 2011

how can we transfer the file from putty session to windows host which resides remotely....

View 1 Replies View Related

General :: Ms-dos 6.22 To File Transfer

Oct 4, 2009

We are having few computers in ms-dos 6.22 , we want to download file from Dos machine to redhat linux machine.

View 4 Replies View Related

Debian :: File Transfer Between Two Computers

Nov 17, 2010

In my laptop with debian-lenny OS I have a number of ripped dvd movies some of which are about 2.5GB. I have transferred those with less than 2GB (that is the size of my usb-flashdrives) to my netbook (with opensuse-11.3 OS) with the help of usb-flashdrives. Is there any method of tranferring the larger files by connecting the two machines by ethernet cables with usb ports and using some software packages?

View 7 Replies View Related

Fedora :: VNC Viewer With File Transfer?

Feb 17, 2010

The last I knew, there still didn't exist a VNC Viewer program for Linux that has UltraVNC or TightVNC file transfer. Is this still the case? I've looked around and so far I haven't found a Linux client that supports either Tight or Ultra file transfer. For example, we are currently connecting to Windoze servers that run UltraVNC server. It would be nice if the Linux VNC client could support file transfer. The alternative is to run the VNC viewers in Wine but I'd rather use a native Linux one if there is such a thing.

View 4 Replies View Related

Fedora :: Transfer File From PC To Pen Drive?

May 25, 2010

How to transfer a file from PC to Pen Drive? I'm having problem in transfering files from my laptop to my pen drive. tell me how to send a file from pc to pen drive.

View 2 Replies View Related

Fedora :: Bluetooth File Transfer On 15 ?

Jun 20, 2011

when i try to transfer a file via bluetooth ,i turn bluetooth ON but i can't toggle "visibility" ON......how do i do it...I even can't add a new device....how do i then transfer file via bluetooth...?

View 4 Replies View Related

OpenSUSE :: File Transfer Notifications

Apr 29, 2011

since i put suse 11.4 (kde 4) on my new laptop there has been something really bugging me. Now, when i transfer files (e.g. from computer to USB HDD) no window pops up, it just runs in the background and uses the notification manager thingy instead. i much preferred having a small pop-up window instead. any ideas on how to get it back like this?

View 3 Replies View Related

OpenSUSE Hardware :: File Transfer Via USB

Apr 26, 2011

I have connected two opensuse-11.3 with a UBS 2.0 Link cable (host-to-host). According to several USB direct file transfer tutorials ifconfig should show me a usb0 device, however I do not see one. How can I establish a file transfer between two linux via USB?

View 4 Replies View Related

General :: Transfer A Zip File That Contains .txt Files Using Ftp Put?

Sep 13, 2011

I am transferring a file from a linux pc going to a windows ftp server using "ftp put". My file is a zip file that includes .txt files inside it. Here is what's happening when I transferred this file :I used ftp put for transferring and found that my transferred zip file was corrupted and couldn't be opened on the ftp server.I found the solution for this on the internet. I needed to use 'binary' to make it right.

I transferred again using binary and then ftp put the zip file onto the other end. Yes, it worked. My zip file wasn't corrupted anymore and I could already opened it on the ftp server. But the problem remains on the .txt files inside it. Converting the file into binary made my .txt files to be distorted and unreadable. I read from the internet that .txt files need to use Ascii instead of Binary to be readable, but if I use ascii it would cause my zip file to be corrupted again. I need to successfully transfer a zip file that contains .txt files using ftp put.

View 5 Replies View Related

Ubuntu Servers :: File Transfer Via Ssh?

Jan 11, 2010

I have my server set up with AjaXplorer but there is a bug in the flash uploader that doesn't let you upload anything to the server.The only way I can update any files or add new ones is to physically plug in an external hard drive or USB drive and transfer them.I have openssh access and that's all set up, but can I transfer files somehow from my laptop to my server using like a cp command?

View 9 Replies View Related

Ubuntu :: Very Slow File Transfer

Feb 14, 2010

i have a bit of a problem and it seems i am not alone, google gave me a lot of hits but no solution.i'm running a dual-boot system on my laptop.

ubuntu 9.10 is installed on ext3
windows xp sp3 on ntfs
files are on another ntfs partition

if i want to copy a file (or folder) bigger than 250mb my laptop literally gives up until the file transfer is complete. opening up a terminal via keyboard shortcut gives my an idea how long a ice age can last.this happens with ext3 to ext3; ext3 to fat32; ext3 to ntfs and ntfs to ntfs.today i wanted to backup some files (12GB ~4k files) the first 4gb ran with 20MB/s (all open applications grayed out). after 2h i came back to see that only 6GB where done.

View 5 Replies View Related

Ubuntu :: 10.04 - Slow USB File Transfer

Jul 9, 2010

Is there any solution for slow file transfers experienced when copying files to usb in 10.04?

View 2 Replies View Related

Ubuntu :: Transfer File Between Drives?

Sep 7, 2010

Ubuntu 10.04 - drive-A, SATA
Windows 7 - driver-B, SATA

The PC is dual boot. I want to transfer a file from drive-A to drive-B.

After starting Ubuntu 10.04 how can I do it?

$ sudo fdisk -l
can't find drive-B

View 1 Replies View Related

Ubuntu :: File Transfer Crashing 10.10?

Oct 16, 2010

I have recently fresh installed ubuntu 10.10 on my Acer Aspire 5940G laptop. and everything seems to be going great apart from i keep on getting random system lockups when i am transfering files from my ipod or usb disk or copying large files on my hard disk.

View 1 Replies View Related

Ubuntu :: Speed Of Scp File Transfer?

May 19, 2011

I have two machines running open vpn connected trough a 8 port Gigabit switch (Tp-link TL-SG1008D). The problem is when I try to transfer a file the transfer starts at 13 mb/s and drops to 300kb/s. When I replaced the ram on the two machines and restarted the transfer the speed was 13mb/s constant. How does changing the ram makes such differences (at the first transfer they had 512mb at the second transfer the machines had only 128mb) ? Os Ubuntu Server 10.04.2 LTS

PS :Tried with 256 ram and the problem persists...
Machines: two hp d530

View 2 Replies View Related

General :: Transfer A File Using Tftp Between Two PC's?

Apr 20, 2011

I am trying to transfer a file using tftp between two PC's. I have installed tftp-server, tftp, xinetd on both PC's. I am unable to transfer the file between the two systems. although the self transfer is working on both the system. I am getting the error "Transfer timed out"

cat /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer

[code]....

View 3 Replies View Related

Ubuntu :: File Transfer Between Two Computers?

Jan 2, 2011

i have 20 pc's in LAN, recently i installed ubuntu server on 2 pc's. i am in need to transfer files between these 2(ubuntu) pc's. i tried sftp but i failed to workout.

View 9 Replies View Related

Networking :: Transfer A File From One Pc - Connected To Lan - To Another One

Nov 16, 2010

I have a lan network. I want to transfer a file from one Pc (connected to Lan) to another one. I know that the best way to do this it's ssh because it's very safe . But i know Samba too. Are there other ways to tranfer a file in a Lan?

View 5 Replies View Related

Networking :: Pidgin File Transfer ?

Jul 26, 2009

I am unable to transfer files in pidgin. I am working under the assumption that I need to create an exception in iptables in order to rectify this problem. I have done a bunch of google searches trying to figure out how to do this specifically to allow file transfers using pidgin.

I am unfamiliar with iptables (I know I know, read the man page) and I'm not sure which port pidgin uses to transfer files. Can anyone help me figure out how to add an exception to so I can transfer files?

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved