I want to create a simple server using GameMaker 1.4. But it's function never works on the first try, no idea why..
var networkType = network_socket_tcp;
var port = 50000;
var maxClients = 32;
var bufferSize = 1024;
var bufferType = buffer_fixed;
var bufferAlign = 1;
server = network_create_server(networkType, port, maxClients);
global.buffer = buffer_create(bufferSize,bufferType,bufferAlign);
sockets = ds_list_create();
if server s_msg("Server is up! Port: " + string(port));
else s_msg("Server is down!");
The message will be "Server down". No matter the port neither the net type.
When I try the same code with a loop, it works on the second try.
Like this:
var networkType = network_socket_tcp;
var port = 50000;
var maxClients = 32;
var bufferSize = 1024;
var bufferType = buffer_fixed;
var bufferAlign = 1;
server = network_create_server(networkType, port, maxClients);
//////////////////////////////////////////////////////
while (!server && port < 65535){
port++;
server = network_create_server(networkType, port, maxClients);
}
//////////////////////////////////////////////////////
global.buffer = buffer_create(bufferSize,bufferType,bufferAlign);
sockets = ds_list_create();
if server s_msg("Server is up! Port: " + string(port));
else s_msg("Server is down!");
Here the message will result on "Server up! Port: 50001".
As I said, no matter the port.. it could be set to 50001 at the beginning resulting on create the server to 50002.
Could someone point my mistake?
SOLUTION (From user Humayun in GM Forums): network_create_server returns an index from 0, so it can't be checked as false/true since the first index would be 0 which returns false. Explains that on the second try i was creating a second instance to the sever variable indexed as 1, and so returning true.
Related
I have an application that I am deploying to AWS on ECS using Terraform. I would like to set it up so that it can perform a health check over HTTP, but require authentication and perform all other activities over HTTPS. However, I have no idea how to set this up and nothing I'm trying is working. Ideally, the HTTPS port should be 8080 (not sure if this is possible, if it's not please advise; it's not a big deal to use a different port). The HTTP port would ideally also be 8080 but can be different as well (I know nothing about networking and not sure if I can hit the same port with 2 different protocols to access 2 different sets of endpoints).
Here's the most recent iteration of what I've tried (abbreviated to only show the parts I think are important); I've tried other things as well but this is the most recent:
resource "aws_ecs_service" "service" {
name = "${var.app_name}-service"
cluster = aws_ecs_cluster.main.id
task_definition = aws_ecs_task_definition.app.arn
desired_count = var.app_count
launch_type = "FARGATE"
health_check_grace_period_seconds = 240
network_configuration {
security_groups = [var.security_group_id]
subnets = var.private_subnet_ids
assign_public_ip = true
}
load_balancer {
target_group_arn = aws_alb_target_group.app.id
container_name = var.app_name
container_port = var.app_port
}
depends_on = [aws_alb_listener.listener]
}
resource "aws_alb_target_group" "app" {
name = "${var.app_name}-target-group"
port = 443
protocol = "HTTPS"
vpc_id = var.vpc_id
target_type = "ip"
health_check {
interval = "30"
protocol = "HTTPS"
matcher = "200-299"
timeout = "3"
path = var.app_health_check_path
unhealthy_threshold = "3"
}
}
resource "aws_alb_listener" "listener" {
load_balancer_arn = var.alb_arn
port = var.alb_listener_port
protocol = "HTTPS"
ssl_policy = "ELBSecurityPolicy-2016-08"
certificate_arn = var.ssl_cert
default_action {
type = "fixed-response"
fixed_response {
content_type = "text/plain"
message_body = "contact admin for ${var.app_name} access"
status_code = 403
}
}
}
resource "aws_lb_listener_rule" "cf_auth_listener_rule" {
listener_arn = aws_alb_listener.listener.arn
priority = 101
action {
type = "forward"
target_group_arn = aws_alb_target_group.app.arn
}
condition {
http_header {
http_header_name = <HEADER_NAME>
values = [<HEADER_VALUE>]
}
}
}
resource "aws_lb_listener_rule" "health_check_listener_rule" {
listener_arn = aws_alb_listener.listener.arn
priority = 1
action {
type = "forward"
target_group_arn = aws_alb_target_group.app.arn
}
condition {
path_pattern {
values = [var.app_health_check_path]
}
}
}
The problem I'm having is that my service is starting, but then immediately shutting down due to failed health check. It seems the ALB can't contact the health check endpoint to perform the health check.
Recently, I started playing around with Game Maker to make a very simple game with the ability to play online (multiplayer). I made a very simple client & server. I can send data from the server to the client, but I can't send the data from the client to the server.
Client: (Create event)
client_socket = network_create_socket(network_socket_tcp);
var server = network_connect(client_socket, "127.0.0.1", 5200);
if(server < 0) show_message("Could not connect! Try turning on the server?");
else{ //Send string
var t_buffer = buffer_create(256, buffer_grow, 1);
buffer_seek(t_buffer, buffer_seek_start, 0);
buffer_write(t_buffer , buffer_string, "Hello");
network_send_packet(client_socket, t_buffer, buffer_tell(t_buffer));
buffer_delete(t_buffer);
}
Server: (Create event)
server_socket = network_create_server(network_socket_tcp, 5200, 5);
(Async Network event)
var n_id = ds_map_find_value(async_load, "id");
if(n_id == server_socket){
var t = ds_map_find_value(async_load, "type");
socketlist = ds_list_create();
if(t == network_type_connect){
var sock = ds_map_find_value(async_load, "socket");
ds_list_add(socketlist, sock);
}
if(t == network_type_data){
var t_buffer = ds_map_find_value(async_load, "buffer");
var cmd_type = buffer_read(t_buffer, buffer_string);
show_message(cmd_type);
}
//show_message("Something happened!");
}
For some reason, the async network event in the server is never triggered when the client sends data. The message Something happened! only comes up when the client either connects or disconnects, but not when data is sent. Using almost the exact same code, I can send from the server, but not vice versa. Is this a problem with the code or just a server/client limitation?
This is the server side code:
var n_id = ds_map_find_value(async_load, "id");
if(n_id == server_socket){
var t = ds_map_find_value(async_load, "type");
socketlist = ds_list_create();
if(t == network_type_connect){
sock = ds_map_find_value(async_load, "socket");
ds_list_add(socketlist, sock);
}
}
if(n_id == sock) {
var t_buffer = ds_map_find_value(async_load, "buffer");
var cmd_type = buffer_read(t_buffer, buffer_string);
show_message(cmd_type);
}
You have to use the socket id when a message is arriving. The network_type_data will never be triggered.
Also, you have to declare the sock variable in the server's create event with a negative number (like noone (-4)).
I am trying to use Ti.Network.TCPSocket to login to an IMAP server.
Its hard as I am not receiving anything back to debug with. For example:
var socket = Ti.Network.createTCPSocket("imap.gmail.com", 993);
socket.connect();
socket.write("LOGIN user pass\r\n");
//event handlers
socket.onWrite(function(data) {
Ti.API.debug('Written to socket: '+data);
});
socket.onError(function(data) {
Ti.API.debug(data);
});
I am not getting anything back. Not even an error or some sort of code or acknowledgement that something is actually happening.
Am I doing something wrong here?
How can I get these even handlers to work or the socket to return some sort of message.
Any help would be appreciated.
UPDATE - Full Code
Ti.API.debug('Start A socket Connection');
var socket = Ti.Network.createTCPSocket("imap.gmail.com", 993);
Ti.API.debug('Connect the socket');
socket.connect();
Ti.API.debug('Socket Connected');
var command = uniqueid()+" LOGIN USER PASS\r\n";
socket.write(command);
//this is where the debug stops. No echo.
Ti.API.debug('Command Run');
socket.onWrite(function(data) {
Ti.API.debug('Written to socket: '+data);
});
socket.onError(function(data) {
Ti.API.debug('Error: '+data);
});
socket.onReadComplete(function(data) {
Ti.API.debug('Here: '+data);
});
function uniqueid() {
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 10; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4";
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
s[8] = s[13] = s[18] = s[23];
var uuid = s.join("");
return uuid;
}
Port 993 is for IMAP over SSL.
onWrite doesn't exist - thats a bug, and probably why your debug statements stop.
try moving your socket.connect() to after you define the handlers.
Use an interval, and socket.isClosed() before trying to write to the socket. Once you get a socket.isClosed() == false, then go ahead. Once you have the socket, you can play with it in the webinspector console in app as well.
This won't solve all your problems, but may help. You might want to try using a utility like wireshark to see what exactly you are sending down the wire when you socket.write, and compare that with what your email client sends.
I posted this in the IIS forums but there has been no replies. So I thought I would try here.
I was using WCAT 5.2 before and that worked ok. I'm trying to run both the client and server and IIS 7 on my local machine. For some reason for every url I request the status is always 400 (bad request) When I look in the htterr logs the reason is says is Hostname???
From httperr log:
#Fields: date time c-ip c-port s-ip s-port cs-version cs-method cs-uri sc-status s-siteid s-reason s-queuename
2010-10-06 04:02:15 127.0.0.1 43252 127.0.0.1 80 HTTP/1.1 GET /ds/test.html 400 - Hostname -
Exe Command
wcat.wsf -terminate -run -t uad.ubr -f settings.ubr -singleip -x
Settings.ubr
settings
{
clientfile = "uad.ubr";
server = "localhost";
clients = 1;
virtualclients = 10;
counters
{
interval = 10;
counter = "Processor(_Total)\\% Processor Time";
counter = "Processor(_Total)\\% Privileged Time";
counter = "Processor(_Total)\\% User Time";
counter = "Processor(_Total)\\Interrupts/sec";
counter = "Memory\\Available KBytes";
counter = "Process(w3wp)\\Working Set";
counter = "System\\Context Switches/sec";
counter = "System\\System Calls/sec";
counter = "Web Service(_Total)\\Bytes Received/sec" ;
counter = "Web Service(_Total)\\Bytes Sent/sec" ;
counter = "Web Service(_Total)\\Connection Attempts/sec" ;
counter = "Web Service(_Total)\\Get Requests/sec" ;
}
registry
{
path = "System\\CurrentControlSet\\Control\\FileSystem";
name = "NtfsDisableLastAccessUpdate";
type = REG_DWORD;
}
registry
{
path = "System\\CurrentControlSet\\Services\\Tcpip\\Parameters";
name = "SynAttackProtect";
type = REG_DWORD;
}
}
Client File (uad.ubr)
scenario
{
warmup = 5;
duration = 10;
cooldown = 5;
default
{
// HTTP1.1 request
version = HTTP11;
}
transaction
{
id = "1";
weight = 1;
request
{
url = "/ds/test.html";
}
}
}
The server returns a 400 bad request because some header information is missing, you need to add a "Host" to the request element.
request
{
url = "/ds/test.html";
setHeader
{
name = "Host";
value = "127.0.0.1";
}
}
I installed a FMS 3.5 on my machine and created a new application with main.asc like this :
application.onAppStart = function()
{
/* Allow debugging */
this.allowDebug = true;
}
//Client is connected
application.onConnect = function( client )
{
//Accept the connection
application.acceptConnection( client );
client.allo = function(o) {
trace("test : " + o ) ;
trace("length : " + o.length ) ;
trace("objectEncoding : " + o.objectEncoding ) ;
return o ;
}
}
//Client disconnected
application.onDisconnect = function( client )
{
//Trace on the FMS Application console
trace( client+" is disconnected" );
}
This code prepare a function I call with my flex application, named "allo" and it returns the same byteArray in response.
The flex code is :
var anotherArray:ByteArray = new ByteArray();
anotherArray.objectEncoding = ObjectEncoding.AMF3;
anotherArray.writeObject(new String("foo"));
nconn.call(func, echoResponder, anotherArray);
As a result, I get an empty ByteArray with only length,encoding, endian and position parameters. And a tcpdump trace shows that the ByteArray is empty.
So I wonder if it's only a pointer which is sent, or maybe I misconfigured something.
Do you know a way to investigate further or solve this ?
Thanks for any help,
MP
I tried your code.
Sending...
var bytes:ByteArray = new ByteArray();
bytes.objectEncoding = ObjectEncoding.AMF3;
bytes.writeObject(new String("foo"));
nc.call("allo", new Responder(_onResult, _onStatus), bytes);
... and receiving...
private function _onResult(result:*):void
{
var bytes:ByteArray = ByteArray(result);
var str:String = String(bytes.readObject());
trace(str);
}
traces foo
I think your code is OK. Only difference is that I use FMS 4.