|
You last visited: Today at 14:25
Advertisement
[C++] Send many string with socket?
Discussion on [C++] Send many string with socket? within the C/C++ forum part of the Coders Den category.
05/29/2014, 16:42
|
#1
|
elite*gold: 0
Join Date: May 2014
Posts: 15
Received Thanks: 0
|
[C++] Send many string with socket?
Hello everyone , I want to send the same string many times with for(),but i've a problem :
Code:
std::string hello = "hello";
for(int i = 0;i<5;i++){
send(socket[i],hello.c_str(),hello.size,0);
}
with the code i want to send the string "hello" 5 times, but the cycle for, send 1 time the string, can you help me? Thanks
|
|
|
05/29/2014, 16:54
|
#2
|
elite*gold: 46
Join Date: Oct 2010
Posts: 782
Received Thanks: 525
|
Why would you do socket[i] ??? Just do
send(socket, hello.c_str(), hello.size, 0);
|
|
|
05/29/2014, 17:06
|
#3
|
elite*gold: 58
Join Date: Jun 2008
Posts: 2,311
Received Thanks: 8,420
|
And maybe you want to include () behind .size ..
Padmak
|
|
|
05/29/2014, 17:10
|
#4
|
elite*gold: 0
Join Date: May 2014
Posts: 15
Received Thanks: 0
|
Quote:
Why would you do socket[i] ??? Just do
send(socket, hello.c_str(), hello.size, 0);
|
I write socket[i] because i want to send the string 5 times with cycle for and no 1
|
|
|
05/29/2014, 17:30
|
#5
|
elite*gold: 46
Join Date: Oct 2010
Posts: 782
Received Thanks: 525
|
Just use
send(socket, hello.c_str(), hello.size(), 0);
And maybe look at for loops. You don't need to write socket[i]. The code will still execute 5 times.
|
|
|
05/29/2014, 20:19
|
#6
|
elite*gold: 0
Join Date: May 2014
Posts: 15
Received Thanks: 0
|
Oh right xD Yes,thanks
|
|
|
05/29/2014, 22:35
|
#7
|
elite*gold: 420
Join Date: Jan 2012
Posts: 1,082
Received Thanks: 1,000
|
If you use a standard container (for example std::array or std::vector) you could just do
for (const auto &s : sockets) send(s, hello.c_str(), hello.length(), 0);
|
|
|
 |
Similar Threads
|
Metin2 Hook Socket Send Function Err
05/09/2014 - C/C++ - 2 Replies
Ich brauche die Hilfe dieser Codes funktionieren nicht :(
#include "stdafx.h"
#include <stdio.h>
#include <Winsock2.h>
#include <windows.h>
#include <iostream>
#include <fstream>
|
[Visual Basic] [Problem] String auslesen/String zufällig wählen
05/06/2012 - General Coding - 4 Replies
Code:
#include <GUIConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Name Generator", 236, 299, 815, 246)
$Input1 = GUICtrlCreateInput("Username", 24, 72, 185, 21)
$Input2 = GUICtrlCreateInput("Username", 24, 104, 185, 21)
$Input3 = GUICtrlCreateInput("Username", 24, 136, 185, 21)
$Input4 = GUICtrlCreateInput("Username", 24, 168, 185, 21)
$Input5 = GUICtrlCreateInput("Username", 24, 200, 185, 21)
|
[Help]C# Postmessage send string
05/03/2012 - .NET Languages - 13 Replies
hey mates,
need some help i know how to send keys:
PostMessage(p.MainWindowHandle, WM_KEYDOWN, (int)Keys.A,1);
PostMessage(p.MainWindowHandle, WM_KEYUP, (int)Keys.A,1);
but i want to send a string to the window i tryed :
foreach (char item in text)
{
PostMessage(p.MainWindowHandle,WM_KEYDOWN,Convert. Int32(item), 1);
PostMessage(p.MainWindowHandle, WM_KEYUP, Convert.Int32(item), 1);
|
Play sound via Packet Send?? [Question String Packet]
07/14/2010 - CO2 Private Server - 5 Replies
Yow im trying to figure out why i cant play music with the string packet
What im doin is;
MyChar.Client.SendPacket(Game.Packet.String(MyCha r.UID, 20, Splitter));
My Packet is:
public byte String(long CharId, byte Type, string name)
|
All times are GMT +1. The time now is 14:26.
|
|