Commit f5ab5edb authored by Robert Scott James's avatar Robert Scott James

Changes to be committed:

	modified:   main.cpp
parent 4b47dbdb
......@@ -3,6 +3,7 @@
#include <stdint.h>
#include <iostream>
#include <string>
#include <cstring>
#include <inttypes.h>
#include <signal.h>
#include <enet/enet.h>
......@@ -14,8 +15,6 @@ void deinitialise(int s){
}
int main() {
fprintf( stderr, "Shutting up\n");
//Enet Initilize
if (enet_initialize () != 0) {
fprintf (stderr, "An error occurred while initializing ENet.\n");
......@@ -48,21 +47,17 @@ int main() {
if(clienthost){
connpeer = enet_host_connect(clienthost, &address, 2, 0);
enet_host_flush(clienthost);
std::cerr << "Connecion good?" << std::endl;
} else {
std::cerr << "Could not connect to server" << std::endl;
return EXIT_FAILURE;
}
//Read
int r;
if (!clienthost){
std::cerr << "Bad clienthost?" << std::endl;
}
while (clienthost){
ENetEvent event;
while(( r=enet_host_service(clienthost, &event, 0))>0){
while( (enet_host_service(clienthost, &event, 0)) > 0 ){
switch(event.type) {
case ENET_EVENT_TYPE_CONNECT:
std::cout << "connected to server" << std::endl;
......@@ -70,19 +65,32 @@ int main() {
case ENET_EVENT_TYPE_RECEIVE:
if (event.channelID == 1){
std::cout << event.packet->data << std::endl;
//std::cout << event.packet->data << std::endl;
unsigned char *datarecv;
size_t packetlength = event.packet->dataLength;
datarecv = (unsigned char *)malloc(packetlength);
std::memcpy(datarecv, event.packet->data,packetlength);
std::cout << "Packet Length: " << packetlength << std::endl;
for(unsigned int i = 0; i < packetlength; i++){
std::cout << datarecv[i];
}
std::cout << std::endl;
free(datarecv);
enet_packet_destroy (event.packet);
} else {
std::cerr << "Data over bad channel" << std::endl;
std::cerr << "Data over another channel: " << event.channelID << std::endl;
}
break;
case ENET_EVENT_TYPE_DISCONNECT:
std::cout << "Disconnect event" << std::endl;
event.peer->data = NULL;
enet_peer_reset (connpeer);
clienthost = NULL;
break;
default: {
std::cout << "Another type of Event" << std::endl;
break;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment