Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (7th_zorro), 1,390 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
a serious network situation #410197
10/30/12 10:58
10/30/12 10:58
Joined: Jul 2011
Posts: 69
P
pjotr987 Offline OP
Junior Member
pjotr987  Offline OP
Junior Member
P

Joined: Jul 2011
Posts: 69
hi guys, in my recent project i tried the network mode of the 3DGS. this causes me some headache now.
the idea behind my project is, that every client has to send an integer matrix (int test_int[20][20][3]) and a var matrix (var[20][20][3]) permanently to all clients. In short words every client has to send this 2 matrices and also receive data in same matrices from other clients permanently for visualisation.
My skills are sadly good anough just to make the script to send single variables but no matrix.

would be great if someone would have mercy with me and give a small and simple example code to do this network job. or atleast some productive suggestions

thanks in advance
pjotr

Re: a serious network situation [Re: pjotr987] #410200
10/30/12 11:20
10/30/12 11:20
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
Hi,

You can perhaps look at send_data_to

Re: a serious network situation [Re: 3dgs_snake] #410204
10/30/12 11:38
10/30/12 11:38
Joined: Jul 2011
Posts: 69
P
pjotr987 Offline OP
Junior Member
pjotr987  Offline OP
Junior Member
P

Joined: Jul 2011
Posts: 69
thanks for reply.
this send_data function seems to be suitable, but i dont understand it fully. as far as i understand from the reference i can understand the following code as following:

typedef struct MYDATA {
int test_int[20][20[3];
var _test_var[20][20[3];


} MYDATA;


that was the definition
so how to fill the metrices with data? i use 2 for loops to insert the data into the matrices. how to do it in this case?

then i send the data with from every client by

// sending data
send_data_to(NULL,mydata,sizeof(MYDATA));

with following function every client should get the data

//receiving data
function on_client_event(void* buffer)
{
if (event_type == EVENT_DATA)
memcpy(mydata,buffer,sizeof(MYDATA));
}

now the second question how to access the data stored in tis 2 matrices that were reiceved with the data?

would be greatefull for any help.
thanks

Re: a serious network situation [Re: pjotr987] #410207
10/30/12 12:05
10/30/12 12:05
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
Hi,

(Not tested wink )
Code:
typedef struct MYDATA
{
   int test_int[20][20][3];
   var test_var[20][20][3];
} MYDATA;

function fill_data(MYDATA *data)
{
   int i = 0;
   int j = 0;
   int k = 0;
   
   for (i = 0; i < 20; i++)
   {
      for (j = 0; j < 20; j++)
      {
        for (k = 0; k < 3; k++)
        {
           data->test_int[i][j][k] = i * j * k;
           data->test_var[i][j][k] = (var)((i * j * k) + 1);
        }
      }  
   }
}
...



You access the data using :
  • if using a normal variable : data.test_int[i][j][k]
  • if using a pointer : data->test_int[i][j][k]

Last edited by 3dgs_snake; 10/30/12 12:11.
Re: a serious network situation [Re: 3dgs_snake] #410216
10/30/12 15:46
10/30/12 15:46
Joined: Jul 2011
Posts: 69
P
pjotr987 Offline OP
Junior Member
pjotr987  Offline OP
Junior Member
P

Joined: Jul 2011
Posts: 69
thanks 3dgs_snake for the explanation,
but i am too dump
to fugure out several things.
1: how to call the function fill_data(MYDATA *data) function, so that the data can be filled. i insert this line in my client code:
send_data_to(NULL,mydata,sizeof(MYDATA)); but it doesnt arrive in another client.

2: how to send the data from a client to another one (if possible a simple function and how to call it)

3: how to receive the data and access it on another client(if possible a simple function and how to call it)

waiting desparately for help laugh

thanks in advance for any trial

Re: a serious network situation [Re: pjotr987] #410244
10/31/12 02:40
10/31/12 02:40
Joined: Dec 2009
Posts: 128
China
frankjiang Offline
Member
frankjiang  Offline
Member

Joined: Dec 2009
Posts: 128
China
I suggest write socket by yourself to do this things,Lite_c`s network is not good.
Code:
#include <string.h>
#include <WINSOCK2.H>
#include <stdio.h>
#pragma comment(lib,"ws2_32.lib")
#include "conf/BufferConf.h"

#include "memPoolList.h"

#include "core/Queue.h"
/*
*
*	
*/
void startRun(ServerObject* t);





DWORD WINAPI listenThreadFun(LPVOID lpParam){
	

	ServerObject* se=Server_getinstance();
	queue* q=se->mProtocolQueue;
	void*pool=memPoolList_get();
	int re;
	while(true){
		re = QueueIsEmpty(q);
		if(re!=1 && se->mQueueLock==0){
			
			se->mQueueLock = 1;
			int i;
			QueueDelete(q,&i);
			SocketProtocol* sp = (SocketProtocol*)i;
			
			ParseData_get(sp);
			
			mempool_free(pool,sp->buffer);
			mempool_free(pool,sp);
			
			printfMemFree(pool);
			
			tool_printf(LOG_DEBUG,"bytes)ParseData_get finish...");
			
			Sleep(1);
			se->mQueueLock = 0;
		}
		Sleep(1);
	}
	return 0;
}
ServerObject* Server_getinstance(){
	if(ser==NULL){
		
		void* pool = memPoolList_get();
		
		ser=(ServerObject*)mempool_malloc(pool,sizeof(ServerObject));
		
		queue* q=QueueInit(10);

		ser->mProtocolQueue = q;
		
		ser->port = 6002;
		
		GameWorld_Instance();
		
		
		HANDLE hThread = CreateThread(NULL,0,listenThreadFun,NULL,0,NULL);
		CloseHandle(hThread);
		ser->mQueueLock = 0;
		
		
		startRun(ser);
	}
	return ser;
}

void startRun(ServerObject* t){
	u_short _port = t->port;
	queue* que = t->mProtocolQueue;
	void*  pool=memPoolList_get();

	if(!t->hWnd){
		
	}

	WORD wVersionRequested;
	WSADATA wsaData;
	int _err;
	wVersionRequested = MAKEWORD(1,1);
	_err = WSAStartup( wVersionRequested, &wsaData );
	if(LOBYTE(wsaData.wVersion)!=1||HIBYTE(wsaData.wVersion)!=1||_err!=0||_port==0){
		WSACleanup();
		return;
	}
	SOCKET sockSrv=socket(AF_INET,SOCK_STREAM,0);
	SOCKADDR_IN addrSrv;
	addrSrv.sin_addr.S_un.S_addr=htonl(INADDR_ANY);
	addrSrv.sin_family=AF_INET;
	addrSrv.sin_port=htons(_port);
	bind(sockSrv,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));
	listen(sockSrv,5);
	SOCKADDR_IN addrClient;
	int len=sizeof(SOCKADDR);

	char rbuf[SOCKET_MAXBUFFER_SIZE];
	int bufferSize = SOCKET_MAXBUFFER_SIZE; 
	memset(rbuf,0,bufferSize);
	printfMemFree(pool);
	while(true){		
		SOCKET _socket=accept(sockSrv,(SOCKADDR*)&addrClient,&len);
		
		
		ParseData_socket((int)_socket);
		
		
		recv(_socket,rbuf,bufferSize,0);
		
		int len;
		ParseData_len(rbuf,&len);
		SocketProtocol* sp=(SocketProtocol*)mempool_malloc(pool,sizeof(SocketProtocol));
		tool_getclientIp(sp->ip,int(_socket),addrClient);
		sp->buffer	=(char*)mempool_malloc(pool,len);
		memcpy(sp->buffer,rbuf,len);
		
		
				
		
		QueueEnter(que,(int)sp);
		

		closesocket(_socket);
	}
}


Last edited by frankjiang; 10/31/12 02:44.

development 3d game is interesting!

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1