Server when using Client and Server on the same machine shuts down upon connection

Hi,

I’m messing with this client and server code for a class I’m in. My professor has run it on his windows computer and it is fine, but when I run it using sublime text 2’s corona editor on my mac in two separate windows it (the server) window closes when I connect (it does connect first, as the server’s connect message does pop up).

Does anyone have any ideas? Is there any sort of bug that might make this crash on a Mac vs. a PC?

Here’s the code (press the red box on the client to invoke the connection):

Client:

local socket = require(“socket”);

local ccX = display.contentCenterX

local ccY = display.contentCenterY

local cW = display.contentWidth

local cH = display.contentHeight

local socket = require(“socket”)

local socket = require(“socket”);

local ip = “localhost”;

local client;

local function CNT (event)

client = socket.connect(ip,20140);

local a, b = client:getsockname(); --this side

print (“Client: I am at:”, a, “:”, b )

local x, y = client:getpeername(); --other side

print (“Client: connected to:”, x, “:”, y);

end

local btnConnect = display.newRect(100,100,100,100);

btnConnect:setFillColor(1,0,0);

btnConnect:addEventListener(“tap”, CNT);

local outMsg = “Hello there:”;

local counter = 0;

local function SND (event)

local sent, msg =

client:send(outMsg…counter…"\r\n");

counter = counter + 1;

print (“sent:”, sent, msg);

end

local button = display.newRect(100, 300, 100, 100);

button:setFillColor(0,1,0);

button:addEventListener(“tap”, SND);

Server:

local socket = require(“socket”);

local server = socket.bind("*", 20140);

local ip, port = server:getsockname();

print(“Server: I am at:”,ip,":",port);

------------------Wait for connection---------------

local client = server:accept();

local cip, cport = client:getpeername();

print (“Server: Connection from: “, cip,”:”, cport);

local function REC (event)

print ("Server: Waiting to receive… ");

local msg, err = client:receive("*l");

print (“Server: received.”);

if msg==nil then

print (“Server: Error.”)

else

print (“Server: Got:”, msg);

end

end

local button = display.newRect(100, 100, 100, 100);

button:addEventListener(“tap”, REC);

local function foo (event)

print (“change box color”);

event.target:setFillColor (math.random(),

math.random(), math.random());

end

local box = display.newRect ( 400, 500, 200,200);

box:addEventListener(“tap”, foo);

I would recommend running Corona Simulator outside of Sublime Text using the “corona Terminal” option.  That way it will stay running.  I’m not sure how ST handles multiple apps running at once.

Rob

I would recommend running Corona Simulator outside of Sublime Text using the “corona Terminal” option.  That way it will stay running.  I’m not sure how ST handles multiple apps running at once.

Rob