LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-28-2005, 06:30 PM   #1
ashucool83
LQ Newbie
 
Registered: Sep 2005
Posts: 11

Rep: Reputation: 0
Sockets Programing Client/Server


Hi I am trying to do multiple send's, but the server only recives the first send and displays the second send as empty:

Client code: (C++ code in Windows 2000 Professional)
send(sd, "A", sizeof("A"), 0);
send(sd, "G", sizeof("A"), 0);

Server code: (C code on QNXOS)
recv(ns,&c,sizeof(char),0);
recv(ns,&d,sizeof(char),0);
printf("Data1: %c", &c);
printf("Data1: %c", &d);

Output on Server:
Data1: A
Data2:

I would appreciate any help regarding the same.

Thanks
 
Old 09-28-2005, 09:31 PM   #2
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
sizeof("A") is 2 because it includes the terminating '\0'

printf("Data1: %c", &d); just reads this final NUL
 
Old 09-29-2005, 12:03 AM   #3
ashucool83
LQ Newbie
 
Registered: Sep 2005
Posts: 11

Original Poster
Rep: Reputation: 0
Hi,

well I had even tried this:-
printf("Data1: %s", &c);
printf("Data1: %s", &d);

It still gave me a balnk on the second recieve ?

Tha
nks
 
Old 09-29-2005, 12:49 AM   #4
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Quote:
Originally posted by ashucool83
Hi,

well I had even tried this:-
printf("Data1: %s", &c);
printf("Data1: %s", &d);

It still gave me a balnk on the second recieve ?

Tha
nks
This is wrong because both c & d aren't string pointers or arrays for you to use %s... They're char's because you're using sizeof(char).

Review C types.
http://www.crasseux.com/books/ctutorial/
 
Old 09-29-2005, 04:30 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,276

Rep: Reputation: 170Reputation: 170
I still don't see the point of sending twice and receiving twice
 
Old 09-29-2005, 12:38 PM   #6
ashucool83
LQ Newbie
 
Registered: Sep 2005
Posts: 11

Original Poster
Rep: Reputation: 0
well actually I want to :-
1.) send command to server (ex- upload .. so it knows what to expect)
2.) send the filesize to server
3.) send the actual file to the server

Thats why I want to do multiple sends and recieves.

ashu
 
Old 09-29-2005, 02:34 PM   #7
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 31
If you are using TCP you can still do that all in one send and just have the server receive it in pieces. (You could have the receiver read the whole stream and parse it afterwards, but that probably complicates it somewhat.)
 
Old 09-29-2005, 03:35 PM   #8
ashucool83
LQ Newbie
 
Registered: Sep 2005
Posts: 11

Original Poster
Rep: Reputation: 0
well I have an options menu like

1) Upload File To Server
2) Download File from Server
3) ...
4) ...

So sending the entire stream once may not be the best idea, coz there are times
when I want to download a file from the server. Thats the reason I want to send the
command first, so the server knows what to do next
1) If Upload then it will wait for file size and the actual file data
2) If Download it will send a file size and the actual file data.

Any better suggestion and help on the initial consecutive send() is highly appreciated.

Thanks
 
Old 09-29-2005, 10:25 PM   #9
ashucool83
LQ Newbie
 
Registered: Sep 2005
Posts: 11

Original Poster
Rep: Reputation: 0
I found something really strange, if the 2nd send() in the client side is replace by:-
send(sd, ch2, 1460, 0); //basically more than 1460

the server is able to get the data of ch2[]. Isnt that weird ???
Any explanations would be higly appreciated.

Thanks
ashu
 
Old 09-30-2005, 02:43 PM   #10
ashucool83
LQ Newbie
 
Registered: Sep 2005
Posts: 11

Original Poster
Rep: Reputation: 0
Hello,

I also get a "Connection Reset By Peer" error when the server is not anle to get the 2nd recv() sent by the client ?? what exactly does that mean and how would I fix it ?

THanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
client/server question (with sockets) bicycle Programming 1 11-24-2005 01:26 PM
Sockets, pthread, pipe, and fork -- a messaging server ggravarr Programming 3 06-28-2005 02:39 PM
Refresh client user list at autentication client/server network. robertoneto123 Linux - Networking 0 11-11-2003 10:38 AM
How to communicate to IMAP/Cyrus server through SOCKETS? Claus Linux - Networking 4 10-31-2003 02:19 PM
Server/Client-commucation via TCP-Sockets cYbORg Programming 5 05-18-2003 06:01 PM


All times are GMT -5. The time now is 09:11 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration