473,396 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sockets, C++, Sending...

2
Hello,
I'm new here :) So please be gentle with me :)

My question: I want to write a Server and a Client with Sockets. It's not the problem but I would want to send not "text-based". And I should be able to send commands like this:

CommandName "Para1" "Para2"...

But of course there exist Commands withouth Parameter, too.

How should I do that in C++? Yes, of course C++ doesnt support that. And I'm under windows. So I use winsock. But I would be very happy to do it on the most portable way ;)

So how would be the best way? I'm frightend because of to small buffers and so on. Especially because of recv()... And later I want to send files, too.

How should I design it at all? I'm thinking how to solve this problems for long time. But.... :(

I hope my problem is understandable.

Thanks :)

Dummie
Jun 21 '07 #1
2 2027
mac11
256 100+
You can send and receive any data you want. You just need to set up a system such that the sender and receiver know what is coming through the socket.

So if you send an int the receiver needs to know that the thing he just received is an int and not 4 chars (for example)

Does this help? I'm not sure how much help you need and I don't want to type for 20 minutes if you only need 3 minutes worth of help (laziness factor!)
Jun 22 '07 #2
Dummie
2
You can send and receive any data you want. You just need to set up a system such that the sender and receiver know what is coming through the socket.

So if you send an int the receiver needs to know that the thing he just received is an int and not 4 chars (for example)

Does this help? I'm not sure how much help you need and I don't want to type for 20 minutes if you only need 3 minutes worth of help (laziness factor!)
This answer help me a little bit. But I still have a (small?) problem. For example I tried this:

Client:

Expand|Select|Wrap|Line Numbers
  1. struct CommandData
  2. {
  3.     int Test1;
  4.     int Test2;
  5.     char *Para;
  6. };
  7.  
  8. CommandData Test;
  9. Test.Test1     =     10;
  10. Test.Test2     =     33924823;
  11. Test.Para      =     "Hello World!";
  12.  
  13. send( Socket, (char *) &Test, sizeof( CommandData ), 0 );
  14.  
Server:

Expand|Select|Wrap|Line Numbers
  1. struct CommandData
  2. {
  3.     int Test1;
  4.     int Test2;
  5.     char *Para;
  6. };
  7.  
  8. CommandData Test;
  9. recv( connectedSocket,(char * ) &Test, 256,0 ); // Whats about the Number 256? What I need to put there?
  10.  
  11. printf( "Received:%s-%i-%i\n", Test.Para, Test.Test1, Test.Test2 ); // Output "Received:-10-33924823"
  12.  
Firstly, is this the right way to do this? I'm very frigthend that I maybe receive not all data. And the struct can't be used.
Another problem is that I don't receive the "char *Para". How I send it on the right way? And how portable is this?

Example:

Server Windows - Client Linux System

What will happen? Does it still work?

Thanks for your help :)
Jun 22 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tero Saarni | last post by:
Hi, I have several threads communicating with each other using events stored in Queues. Threads block on Queue.get() until somebody publishes an event in thread's event queue. I need to add...
1
by: Tim Black | last post by:
My application requires sending a large piece (~2MB) of data to several devices on a network via TCP sockets. I have experimented with different methods for doing this and this has raised some...
3
by: Robert A. van Ginkel | last post by:
In news:OZ0W9RsdDHA.2432@TK2MSFTNGP10.phx.gbl... I ask the question how I can see if all the data is on the other side of the connection. I got as answer that I should use the blocking property. I...
6
by: Laxmikant Rashinkar | last post by:
Is there any way to use a C# socket in promiscuous mode? Any sample code that shows how this is done? any assistance is much appreciated! thanks LK
0
by: Stuart Norris | last post by:
Dear Group, I am having a problem setting SocketOptionName.SendTimeout on a client TCPIP application using the sockets in .NET. From the on-line help it is possible to set a...
4
by: WAkthar | last post by:
I am in the process of converting an MFC client and server application to C#. The communication between the client and server was done using simple WM_COPYDATA. I want to use sockets for the C#...
3
by: J C | last post by:
Hi, I'm using UDPClient to make a simple DNS server. I notice that intermittently and unpredictibly I get: Unhandled Exception: System.Net.Sockets.SocketException: An existing connection...
0
by: J008 | last post by:
Just looking for some insight as to why the callback "BeginReceiveFromCallback" is not being called in my "Receive" Subroutine below (when I call BeginReceiveFrom). I am trying to read data...
14
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.