Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
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
4 registered members (AbrahamR, 7th_zorro, dr_panther, 1 invisible), 702 guests, and 6 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
problem about socket_ function #337493
08/11/10 08:59
08/11/10 08:59
Joined: Nov 2007
Posts: 14
D
druid Offline OP
Newbie
druid  Offline OP
Newbie
D

Joined: Nov 2007
Posts: 14
i was woking on A7 7.84 pro about socket.but there is a problem that:
the socket_connect and socket_send work fine in one program.(like the example code)

but when i use it in two programs like server.c and client.c (whatever they are both runned on the same computer or in the same network) the socket_recieve() returns 0 and nothing received.

can the socket_ function run in different program?or it can only run in one program?

Code:
#include <acknex.h>
#include <default.c>
#include <d3d9.h>
STRING* l_C_Server_Address = "127.0.0.1";
var l_C_Port_Num = 1234;
TEXT* txtReceive = { flags = SHOW; }

function main()
{
	level_load("");
	wait(3);
	if (!socket_connect(l_C_Server_Address, l_C_Port_Num, 0)) {
      printf("Can't connect to GalepX!");
   } else {

		char input;
		
	   while(1) {
        	wait(1);
// receive the response   
        	int received = socket_receive(input,str_len("d"));
        	if (received) {
        		input[received]=0;
        		printf(input);
// display the response   
          	// input[received] = 0; // add '0' end mark
          	txt_addstring(txtReceive,input);
        	}
		}

	}
}


Code:
#include <acknex.h>
#include <default.c>
#include <d3d9.h>
STRING* l_C_Server_Address = "127.0.0.1";
var l_C_Port_Num = 1234;
TEXT* txtReceive = { flags = SHOW; }

function main()
{
	level_load("");
	wait(3);
	if (!socket_connect(l_C_Server_Address, l_C_Port_Num, 0)) {
      printf("Can't connect to GalepX!");
   } else {
	
	
		while(1){
			socket_connect(l_C_Server_Address, l_C_Port_Num, 0);
			if(key_s)socket_send(_chr("s"),str_len("s"));
			if(key_d)socket_send(_chr("d"),str_len("d"));
			wait(1);
		}
	}
}



plz hlep me have a look at what's the problem

the source code is like the attachment.

Re: problem about socket_ function [Re: druid] #337496
08/11/10 09:32
08/11/10 09:32
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
This is no server code, I see only two different client codes. For socket communication you need a socket server. I think you can establish a socket server by calling session_open but I havent tried it.

For sending between two programs I do not use socket functions, but send_data, this works fine and has a more reliable protocol than socket communication. You can check out the pong_multiplayer.c for an example.

Re: problem about socket_ function [Re: Spirit] #337500
08/11/10 09:52
08/11/10 09:52
Joined: Nov 2007
Posts: 14
D
druid Offline OP
Newbie
druid  Offline OP
Newbie
D

Joined: Nov 2007
Posts: 14
thank u spirit

i use these two code just for test UDP. in the project i have to communicate with an other VB program. so i want to try A7 udp connection first and then test with VB program.

as u said i have to create a UDP server first with session_open, i will try that immediately .

if that works i will put my test code here.

Re: problem about socket_ function [Re: druid] #337501
08/11/10 10:05
08/11/10 10:05
Joined: Nov 2007
Posts: 14
D
druid Offline OP
Newbie
druid  Offline OP
Newbie
D

Joined: Nov 2007
Posts: 14
it works,as spirit said that socket_connect function need a UDP server first.i have tried the VB program and it has received the data.

i think that session_ function is used for session_connect and session_open not UDP .
next time i will try that out.

thank Spirit for the information. Great help


Moderated by  HeelX, Spirit 

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