本文整理汇总了C++中TcpSocket::send方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpSocket::send方法的具体用法?C++ TcpSocket::send怎么用?C++ TcpSocket::send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpSocket
的用法示例。
在下文中一共展示了TcpSocket::send方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: broadcast
void TcpSocketServer::broadcast(DataToSend* data)
{
if (data == NULL) return;
if (data->getType() != DataToSend::DS_READER)
{
for (Clients::iterator itr = _clients.begin(), end = _clients.end(); itr != end; ++itr)
{
TcpSocket* client = *itr;
client->send(data);
}
}
else
{
Ref<StreamReader> reader = data->getReader();
ASSERT_THROW(reader->isSeekable(), EX_NOT_SUPPORTED);
size_t pos = reader->tell();
for (Clients::iterator itr = _clients.begin(), end = _clients.end(); itr != end; ++itr)
{
reader->seek(pos);
TcpSocket* client = *itr;
client->send(data);
}
}
}
示例2: c_communication
void c_communication(c_serveur& sett)
{
TcpSocket svr;
svr.connect(sett.c_ip,55001);
c_infoPlayer<<c_pseudo;
svr.send(c_infoPlayer);
cout<<"Communication lancee"<<endl;
while(c_connected)
{
c_attendre.lock();
svr.send(c_sortant);
c_sortant.clear();
c_sortant<<false<<"";
c_attendre.unlock();
bool a;
string b;
if(svr.receive(c_entrant) == Socket::Done)
{
//system("cls");
c_entrant>>a>>b;
if(!a)
c_msgsRecus = b;
}
else
{
示例3: tcpSocketTest
bool SocketTest::tcpSocketTest()
{
SimpleServer server;
server.start();
System::Sleep(500);
TEST_ASSERT(server.start_flag)
TEST_ASSERT_MSG(server.bind_flag, server.msg.text())
TEST_ASSERT_MSG(!server.aborted, server.msg.text())
// create tcp socket
TcpSocket client;
client.connect(TCP_TEST_HOST, TCP_TEST_PORT);
TEST_ASSERT(client.getRemoteAddress().getPort() == TCP_TEST_PORT);
client.send(TEST_MESSAGE1);
TEST_ASSERT_MSG(!server.aborted, server.msg.text())
System::Sleep(100);
TEST_ASSERT_MSG(!server.aborted, server.msg.text())
TEST_ASSERT(server.msg1_flag)
// test if something is already running on a port
Socket psocket;
TEST_THROWS(psocket.bind(TCP_TEST_PORT), Net::Errors::SocketException);
String in;
client.readUntil(in, '!');
TEST_ASSERT(in == TEST_MESSAGE2);
client.readUntil(in, '.', 2000);
TEST_ASSERT_MSG(in == TEST_MESSAGE3, in.text());
client.readUntil(in, '!', 2000);
TEST_ASSERT(in == TEST_MESSAGE4);
client.readUntil(in, "#@", 2000);
TEST_ASSERT(in == TEST_MESSAGE5);
return true;
}
示例4: send_random_curve
string send_random_curve(TcpSocket& stream)
{
string curveData = readRandomCurve();
Packet pkt;
pkt << curveData;
// Send curve
stream.send(pkt);
return curveData;
}
示例5: main
int main()
{
socket.receive(recvChar, 1024, received);
cout << recvChar << endl;
Socket::Status status = socket.connect("localhost", 10006);
socket.send(sendChar, 1024);
return 0;
}
示例6: sizeof
static TcpSocket *clientConnect(SOCKET serverSocket, sockaddr_in *host)
{
sockaddr_in hostTemp;
int hostSize = sizeof(sockaddr_in);
SOCKET clientSocket = accept(serverSocket, (sockaddr*)&hostTemp, &hostSize);
if (INVALID_SOCKET == clientSocket)
return NULL;
const char *expectedGreeting = CLIENT_GREET;
std::string line;
line.resize(0);
for (;;) {
char ch;
if (recv(clientSocket, &ch, 1, 0) != 1) {
closesocket(clientSocket);
return NULL;
}
if (ch == '\n')
break;
if (ch != '\r')
line.push_back(ch);
if (ch == '!')
break;
}
TcpSocket *ret = NULL;
if (!line.compare(0, 4, "GET ")) {
ret = WebSocket::upgradeFromHttp(clientSocket);
line.resize(strlen(expectedGreeting));
if (!ret || !ret->recv(&line[0], line.length())) {
closesocket(clientSocket);
return NULL;
}
} else
ret = new TcpSocket(clientSocket);
if (line.compare(0, strlen(expectedGreeting), expectedGreeting) ||
!ret->send(SERVER_GREET, strlen(SERVER_GREET), true)) {
ret->disconnect();
return NULL;
}
if (NULL != host)
*host = hostTemp;
return ret;
}
示例7: own_thread
void Client::own_thread()
{
TcpSocket sock;
sock.connect( m_host, m_port );
unsigned int version = 1;
unsigned int options = 0;
sock.send( version );
sock.send( options );
// first send size of name.
sock.sendString( m_name );
unsigned int images = 0;
unsigned int width = 0;
unsigned int height = 0;
unsigned int bpp = 0;
try
{
sock.receive( images );
sock.receive( width );
sock.receive( height );
sock.receive( bpp );
} catch( std::string a_error )
{
std::cerr << a_error << std::endl;
return ;
}
std::cout << "DEBUG: " << "images: " << images << " w: " << width << " h: " << height << " bpp: " << bpp << std::endl;
std::unique_ptr< sepia::Writer > data = std::unique_ptr< sepia::Writer >( new sepia::Writer( m_name, images, width, height, bpp ) );
int more = 0; // more data available if true.
while( !m_terminate )
{
for( int i = 0; i < data->getGroupHeader()->count; i++ )
{
sock.receive( *data->getHeader( i ) );
sock.receive( data->getAddress( i ), data->getSize( i ) );
}
data->update();
}
}
示例8: main
int main()
{
Socket::Status status = socket.connect("localhost", 10004);
socket.send(sendChar, 1024);
buidMap();
/////build threads
Thread sendrecvThread(&sendRecv);
Thread mainGameThread(&mainGame);
Thread pressButtonThread(&pressButton);
/////launch threads
sendrecvThread.launch();
pressButtonThread.launch();
mainGameThread.launch();
/////////////////////////////////////
return 0;
}
示例9: send_key
void send_key(TcpSocket& stream, PointRef p)
{
char *bgxBuffer = NULL;
char *bgyBuffer = NULL;
string bgxString, bgyString;
Packet pkt;
gmp_asprintf(&bgxBuffer, "%Zd", p->x);
gmp_asprintf(&bgyBuffer, "%Zd", p->y);
bgxString = string(bgxBuffer);
bgyString = string(bgyBuffer);
free(bgxBuffer), bgxBuffer = NULL;
free(bgyBuffer), bgyBuffer = NULL;
pkt << bgxString;
pkt << bgyString;
stream.send(pkt);
cout << "Sent (" << bgxString << ", " << bgyString << ")" << endl;
}
示例10: sendRecv
////////////////////////////////////////////////////send & recv from server
void sendRecv()
{
while (1)
{
socket.receive(recvChar, 1024, received);
cout << recvChar << endl;
if (recvChar[0] != anotherClient)
{
for (int i0 = 0; i0 < tank.size(); i0++)
{
sendChar[i0] = playerButton[i0];
}
for (int i1 = 0; i1 < tank.size(); i1++)
{
for (int i2 = 0; i2 < 7; i2++)
{
tank[i1].button[i2] = recvChar[7 * i1 + i2];
cout << tank[i1].button[i2] << endl;
}
}
///making send char for normal use
sendChar[0] = playerID;
for (int i0 = 0; i0 < 7; i0++)
{
sendChar[i0 + 1] = playerButton[i0];
}
socket.send(sendChar, 1024);
}
else
{
sendChar[0] = wall.size();
for (int j0 = 0; j0 < wall.size(); j0++)
{
sendChar[wall[j0].tedadeVizhegiha*j0 + 1] = wall[j0].ID;
sendChar[wall[j0].tedadeVizhegiha*j0 + 2] = wall[j0].centerPoint.x;
sendChar[wall[j0].tedadeVizhegiha*j0 + 3] = wall[j0].centerPoint.y;
sendChar[wall[j0].tedadeVizhegiha*j0 + 4] = wall[j0].length;
sendChar[wall[j0].tedadeVizhegiha*j0 + 5] = wall[j0].width;
sendChar[wall[j0].tedadeVizhegiha*j0 + 6] = wall[j0].leftUpPoint.x;
sendChar[wall[j0].tedadeVizhegiha*j0 + 7] = wall[j0].leftUpPoint.y;
sendChar[wall[j0].tedadeVizhegiha*j0 + 8] = wall[j0].rightDownPoint.x;
sendChar[wall[j0].tedadeVizhegiha*j0 + 9] = wall[j0].rightDownPoint.y;
}
sendChar[(wall.size()*wall[0].tedadeVizhegiha) + 1] = bullet.size();
for (int j0 = wall.size()*wall[0].tedadeVizhegiha + 1; j0 < wall.size()*wall[j0].tedadeVizhegiha + 1 + bullet.size(); j0++)
{
sendChar[bullet[j0].tedadeVizhegiha*j0 + 1] = bullet[j0].ID;
sendChar[bullet[j0].tedadeVizhegiha*j0 + 2] = bullet[j0].tankID;
sendChar[bullet[j0].tedadeVizhegiha*j0 + 3] = bullet[j0].centerPoint.x;
sendChar[bullet[j0].tedadeVizhegiha*j0 + 4] = bullet[j0].centerPoint.y;
sendChar[bullet[j0].tedadeVizhegiha*j0 + 5] = bullet[j0].radius;
sendChar[bullet[j0].tedadeVizhegiha*j0 + 6] = bullet[j0].velocity.x;
sendChar[bullet[j0].tedadeVizhegiha*j0 + 7] = bullet[j0].velocity.y;
}
sendChar[wall.size()*wall[0].tedadeVizhegiha + (bullet.size()*bullet[0].tedadeVizhegiha) + 2] = tank.size();
for (int j0 = wall.size()*wall[0].tedadeVizhegiha + (bullet.size()*bullet[0].tedadeVizhegiha) + 2; j0 < wall.size()*wall[0].tedadeVizhegiha + (bullet.size()*bullet[0].tedadeVizhegiha) + tank.size() + 2; j0++)
{
sendChar[tank[j0].tedadeVizhegiha*j0 + 1] = tank[j0].forwardVelocity;
sendChar[tank[j0].tedadeVizhegiha*j0 + 2] = tank[j0].backwardVelocity;
sendChar[tank[j0].tedadeVizhegiha*j0 + 3] = tank[j0].bodyRotationVelocity;
sendChar[tank[j0].tedadeVizhegiha*j0 + 4] = tank[j0].pipeRotationVelocity;
sendChar[tank[j0].tedadeVizhegiha*j0 + 5] = tank[j0].vecForwardVelocity.x;
sendChar[tank[j0].tedadeVizhegiha*j0 + 6] = tank[j0].vecForwardVelocity.y;
sendChar[tank[j0].tedadeVizhegiha*j0 + 7] = tank[j0].vecBackwardVelocity.x;
sendChar[tank[j0].tedadeVizhegiha*j0 + 8] = tank[j0].vecBackwardVelocity.y;
sendChar[tank[j0].tedadeVizhegiha*j0 + 9] = tank[j0].ID;
sendChar[tank[j0].tedadeVizhegiha*j0 + 10] = tank[j0].centerPoint.x;
sendChar[tank[j0].tedadeVizhegiha*j0 + 11] = tank[j0].centerPoint.y;
sendChar[tank[j0].tedadeVizhegiha*j0 + 12] = tank[j0].length;
sendChar[tank[j0].tedadeVizhegiha*j0 + 13] = tank[j0].width;
sendChar[tank[j0].tedadeVizhegiha*j0 + 14] = tank[j0].bodyDegree;
sendChar[tank[j0].tedadeVizhegiha*j0 + 15] = tank[j0].bodyRotateSpeed;
sendChar[tank[j0].tedadeVizhegiha*j0 + 16] = tank[j0].pipeDegree;
sendChar[tank[j0].tedadeVizhegiha*j0 + 17] = tank[j0].pipeRotateSpeed;
sendChar[tank[j0].tedadeVizhegiha*j0 + 18] = tank[j0].velocity.x;
sendChar[tank[j0].tedadeVizhegiha*j0 + 19] = tank[j0].velocity.y;
}
}
for (int i = 0; i < recvChar[0]; i++)
{
wall[i + 1].ID = recvChar[i*wall[0].tedadeVizhegiha + 1];
wall[i + 1].centerPoint.x = recvChar[i*wall[0].tedadeVizhegiha + 2];
wall[i + 1].centerPoint.y = recvChar[i*wall[0].tedadeVizhegiha + 3];
wall[i + 1].length = recvChar[i*wall[0].tedadeVizhegiha + 4];
wall[i + 1].width = recvChar[i*wall[0].tedadeVizhegiha + 5];
wall[i + 1].leftUpPoint.x = recvChar[i*wall[0].tedadeVizhegiha + 6];
wall[i + 1].leftUpPoint.y = recvChar[i*wall[0].tedadeVizhegiha + 7];
wall[i + 1].rightDownPoint.x = recvChar[i*wall[0].tedadeVizhegiha + 8];
wall[i + 1].rightDownPoint.y = recvChar[i*wall[0].tedadeVizhegiha + 9];
}
for (int i = (recvChar[0] * wall[0].tedadeVizhegiha) + 1; i < recvChar[(recvChar[0] * wall[0].tedadeVizhegiha) + 1]; i++)
{
bullet[i + 1].ID = recvChar[(recvChar[0] * wall[0].tedadeVizhegiha) + (i*bullet[0].tedadeVizhegiha) + 2];
bullet[i + 1].tankID = recvChar[(recvChar[0] * wall[0].tedadeVizhegiha) + (i*bullet[0].tedadeVizhegiha) + 3];
bullet[i + 1].centerPoint.x = recvChar[(recvChar[0] * wall[0].tedadeVizhegiha) + (i*bullet[0].tedadeVizhegiha) + 4];
bullet[i + 1].centerPoint.y = recvChar[(recvChar[0] * wall[0].tedadeVizhegiha) + (i*bullet[0].tedadeVizhegiha) + 5];
//.........这里部分代码省略.........