Modify server and client to begin using ClientToServer messages.
This commit is contained in:
parent
0104a11a7e
commit
c043da64a2
|
@ -4,9 +4,11 @@ SilverMUDServer_CFLAGS = -I/usr/include/guile/3.0 -I/usr -lguile-3.0 -lgc -lpthr
|
||||||
SilverMUDClient_CFLAGS = -I/usr/include/guile/3.0 -I/usr -lguile-3.0 -lgc -lpthread -ldl -lgnutls -g
|
SilverMUDClient_CFLAGS = -I/usr/include/guile/3.0 -I/usr -lguile-3.0 -lgc -lpthread -ldl -lgnutls -g
|
||||||
|
|
||||||
SilverMUDServer_SOURCES = \
|
SilverMUDServer_SOURCES = \
|
||||||
|
source/messages.c \
|
||||||
source/server/connections.c \
|
source/server/connections.c \
|
||||||
source/server/scheme-integration.c \
|
source/server/scheme-integration.c \
|
||||||
source/server/main.c
|
source/server/main.c
|
||||||
|
|
||||||
SilverMUDClient_SOURCES = \
|
SilverMUDClient_SOURCES = \
|
||||||
|
source/messages.c \
|
||||||
source/client/main.c
|
source/client/main.c
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <gnutls/gnutls.h>
|
#include <gnutls/gnutls.h>
|
||||||
|
|
||||||
|
#include "../messages.h"
|
||||||
|
|
||||||
int main (int argc, char ** argv)
|
int main (int argc, char ** argv)
|
||||||
{
|
{
|
||||||
// Print a welcome message:
|
// Print a welcome message:
|
||||||
|
@ -64,11 +66,11 @@ int main (int argc, char ** argv)
|
||||||
while (returnValue < 0 && gnutls_error_is_fatal(returnValue) == 0);
|
while (returnValue < 0 && gnutls_error_is_fatal(returnValue) == 0);
|
||||||
|
|
||||||
|
|
||||||
char buffer[2048];
|
struct ClientToServerMessage message;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
fgets(buffer, 2048, stdin);
|
fgets(message.content, 1024, stdin);
|
||||||
gnutls_record_send(tlsSession, &buffer, 2048);
|
gnutls_record_send(tlsSession, &message, 1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a successful status code to the operating system:
|
// Return a successful status code to the operating system:
|
||||||
|
|
|
@ -39,7 +39,7 @@ SCM scheme_createClientToServerMessage(SCM content)
|
||||||
free(contentString);
|
free(contentString);
|
||||||
|
|
||||||
// Return the pointer as a Scheme object:
|
// Return the pointer as a Scheme object:
|
||||||
return scm_from_pointer(message);
|
return scm_from_pointer(message, NULL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -87,7 +87,7 @@ SCM scheme_createServerToClientMessage(SCM type, SCM name, SCM content)
|
||||||
free(contentString);
|
free(contentString);
|
||||||
|
|
||||||
// Return the pointer as a Scheme object:
|
// Return the pointer as a Scheme object:
|
||||||
return scm_from_pointer(message);
|
return scm_from_pointer(message, NULL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,9 +6,8 @@
|
||||||
#ifndef MESSAGES_H
|
#ifndef MESSAGES_H
|
||||||
#define MESSAGES_H
|
#define MESSAGES_H
|
||||||
#include <libguile.h>
|
#include <libguile.h>
|
||||||
|
#define MESSAGE_NAME_LENGTH 128
|
||||||
const size_t MESSAGE_NAME_LENGTH = 128;
|
#define MESSAGE_CONTENT_LENGTH 1024
|
||||||
const size_t MESSAGE_CONTENT_LENGTH = 1024;
|
|
||||||
|
|
||||||
enum MessageTypes
|
enum MessageTypes
|
||||||
{
|
{
|
||||||
|
@ -22,7 +21,7 @@ enum MessageTypes
|
||||||
|
|
||||||
struct ClientToServerMessage
|
struct ClientToServerMessage
|
||||||
{
|
{
|
||||||
char content[MESSAGE_CONTENT_LENGTH]
|
char content[MESSAGE_CONTENT_LENGTH];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ServerToClientMessage
|
struct ServerToClientMessage
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <gnutls/gnutls.h>
|
#include <gnutls/gnutls.h>
|
||||||
|
|
||||||
#include "connections.h"
|
#include "connections.h"
|
||||||
|
#include "../messages.h"
|
||||||
#include "scheme-integration.h"
|
#include "scheme-integration.h"
|
||||||
|
|
||||||
static const int PORT = 5000;
|
static const int PORT = 5000;
|
||||||
|
@ -161,7 +162,7 @@ int main (int argc, char ** argv)
|
||||||
addNewConnection(&clientConnections, newSocket, tlsSession);
|
addNewConnection(&clientConnections, newSocket, tlsSession);
|
||||||
|
|
||||||
// Print a message:
|
// Print a message:
|
||||||
printf("New connection established! %d clients, session ID %d.\n", clientConnections.clientCount, tlsSession);
|
printf("New connection established! %d clients, session ID %u.\n", clientConnections.clientCount, tlsSession);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -169,8 +170,8 @@ int main (int argc, char ** argv)
|
||||||
struct ClientConnection * connection = findConnectionByFileDescriptor(&clientConnections, events[index].data.fd);
|
struct ClientConnection * connection = findConnectionByFileDescriptor(&clientConnections, events[index].data.fd);
|
||||||
if (connection != NULL)
|
if (connection != NULL)
|
||||||
{
|
{
|
||||||
char buffer[2048];
|
struct ClientToServerMessage message;
|
||||||
int returnValue = gnutls_record_recv(*connection->tlsSession, &buffer, 2048);
|
int returnValue = gnutls_record_recv(*connection->tlsSession, &message, sizeof(struct ClientToServerMessage));
|
||||||
if (returnValue == 0 || returnValue == -10)
|
if (returnValue == 0 || returnValue == -10)
|
||||||
{
|
{
|
||||||
printf("Closing session ID: %d\n", *connection->tlsSession);
|
printf("Closing session ID: %d\n", *connection->tlsSession);
|
||||||
|
@ -180,9 +181,9 @@ int main (int argc, char ** argv)
|
||||||
close(connection->fileDescriptor);
|
close(connection->fileDescriptor);
|
||||||
removeConnectionByFileDescriptor(&clientConnections, connection->fileDescriptor);
|
removeConnectionByFileDescriptor(&clientConnections, connection->fileDescriptor);
|
||||||
}
|
}
|
||||||
else if (returnValue == 2048)
|
else if (returnValue == sizeof(struct ClientToServerMessage))
|
||||||
{
|
{
|
||||||
printf("%s", buffer);
|
printf("%s", message.content);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue