Programming 2D Games
http://programming2dgames.com/forum/

A question of port
http://programming2dgames.com/forum/viewtopic.php?f=4&t=366
Page 1 of 1

Author:  KDK1976 [ Wed Oct 04, 2017 6:45 pm ]
Post subject:  A question of port

Chapter 12 “If more than one application running on a computer uses the same port, a conflict will result “

Can you just expand on this, does this mean that it will not work at all?

Is there a way to check and maybe use a different port?


Cheers :)

Author:  profkelly [ Fri Oct 06, 2017 12:33 pm ]
Post subject:  Re: A question of port

https://www.howtogeek.com/howto/28609/how-can-i-tell-what-is-listening-on-a-tcpip-port-in-windows/

Your game code should allow the user to specify the port to use.

Author:  KDK1976 [ Mon Oct 16, 2017 7:49 pm ]
Post subject:  Re: A question of port

OK I’ve managed to answer my question on checking for a used port in my program. Code is as follows

Code:
int                                         iCheck,
                                            iX;
 
iX =                                        0;
 
//Loop/If-----------------------------------*-------------|                           |
do
{
   APP_SERVER_PORT +=            iX;

   iCheck =
    cServer->CreateServer(                 APP_SERVER_PORT,
                                            APP_PROTOCOL);
 
    iX +=                                    1;
 
} while (iCheck != NET_OK);



Now all I need to know is sending custom structures. Am I correct in thinking that when using the ReadData function, the Size variable needs to be set to the expected size and the Data And SenderIP are blank pointers that receive the data and sender IP?

Is it possible to create a server and client on different ports within the same app and send data to each other or do they have to be in separate apps. It’s just I’m trying to test sending a custom structure and it is easier to debug In one app. My game initialisation has the following code.

Code:
//------------------------------------------*-----------------------------------------|
int               
UDP =                              0,
TCP =                              1,

APP_SERVER_PORT =                     5123,
APP_CLIENT_PORT =                     4072
APP_PROTOCOL =                        TCP;

//------------------------------------------*-----------------------------------------|
const char               
SERVER_IP_ADDRESS[] =                  "192.168.1.189";

//------------------------------------------*-----------------------------------------|
cNetwork                           *cServer,
                                 *cClient;

cServer = new                         cNetwork;
cClient = new                        cNetwork;

//------------------------------------------*-----------------------------------------|

int                                         iCheck,
                                            iX;
 
iX =                                        0;
 
//Loop/If-----------------------------------*-------------|                           |
do
{
        APP_SERVER_PORT +=            iX;

   iCheck =
    cServer->CreateServer(                 APP_SERVER_PORT,
                                            APP_PROTOCOL);
 
    iX +=                                    1;
 
} while (iCheck != NET_OK);
 
iX =                                        0;

//Loop/If-----------------------------------*-------------|                           |
do
{
        APP_CLIENT_PORT +=        iX;

      iCheck =
    cClient->CreateClient(                  (char*)SERVER_IP_ADDRESS,
                                            APP_CLIENT_PORT,
                                            APP_PROTOCOL);
 
      iX +=                                 1;
 
} while (iCheck != NET_OK);
 
//------------------------------------------*-----------------------------------------|
char                                        *iSenderIP,
                                            *iFileData;

int                                         iSize;
 
sAuth                                       *iAuth;

//------------------------------------------*-----------------------------------------|
iAuth->Email =                                 "john.smith@hotmail.co.uk";
iAuth->LicenceKey =                          "1546.3795.6248.6428";
iAuth->Password =                             "Password001";
iAuth->UpdateDate.D =                        12;
iAuth->UpdateDate.M =                        10;
iAuth->UpdateDate.Y =                        2017;
iAuth->Username =                            "John Smith";
 
iSize =                                     sizeof(sAuth);

//------------------------------------------*-----------------------------------------|
iCheck =
cClient->SendData(                         (char*)iAuth,
                                            iSize,
                                            (char*)SERVER_IP_ADDRESS,
                                            APP_SERVER_PORT);

//Loop/If-----------------------------------*-------------|                           |
if (iCheck != NET_OK)
{
    std::string                              iError;
    
    iError = cClient->GetError(             iCheck);   
}


My game loop has the following.


Code:
//------------------------------------------*-----------------------------------------|
char                                        *iSenderIP,
                                            *iFileData;

int                                         
iSize =                              sizeof(sAuth);
 
sAuth                                       *iAuth;

//------------------------------------------*-----------------------------------------|
iCheck =
cServer->ReadData(                         iFileData,
                                            iSize,
                                            (char*)iSenderIP);

//Loop/If-----------------------------------*-------------|                           |
if (iCheck != NET_OK)
{
    std::string
   iError = cServer->GetError(             iCheck);
}

//Loop/If-----------------------------------*-------------|                           |
else
{
   iAuth =                                  (sAuth*)iFileData;
}



sAuth is my custom structure. The server never receives any data. iError always states no network errors.

What is it that I’m doing wrong?


Many thanks :)

Author:  profkelly [ Tue Oct 17, 2017 2:26 pm ]
Post subject:  Re: A question of port

KDK1976 wrote:
Is it possible to create a server and client on different ports within the same app and send data to each other or do they have to be in separate apps. It’s just I’m trying to test sending a custom structure and it is easier to debug In one app.

Hmmm? I think it would be possible but I would need to write some test code to be sure. Each client/server connection would require a unique socket that specifies the port to use. Unfortunately I don't have any free time to experiment at the moment.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/