Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (howardR, 7th_zorro), 893 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
socket_connect.... socket_send,,, #423395
05/29/13 08:33
05/29/13 08:33
Joined: Nov 2008
Posts: 28
Athens, Greece
NeoJT Offline OP
Newbie
NeoJT  Offline OP
Newbie

Joined: Nov 2008
Posts: 28
Athens, Greece
Hi and sorry for my english

Im trying to comunicate 2 servers.

The Sender send a message to Receiver when the player
hit the f5 : ( this is for testing the communication )

inside the Server-Sender

Code:
STRING* l_temp_1_str = " ";

while(1)
{
   if (key_f5)
   {
      while(key_f5)
      {
         wait(1);
      }
      //----------------------------------
      // I use port "2300" for Server-Received and "2301" for Server-Sender
      //----------------------------------     
      if ( !socket_connect( "127.0.0.1", "2300", 1 ) ) 
      {
         printf("Can't connect to login server");
      }
      else
      {
         printf("Connect to login server");
         					
         str_cpy(l_temp_1_str, "From Sender : message sending");
         var size = str_len(l_temp_1_str);
         var sent = socket_send(_chr(l_temp_1_str),size);
         if (sent) 
         {
            printf("message send ok");
         }
      }
   }
   wait(1);
}



-----------------------------------------
and inside the Server-Receiver

Code:
while(1) 
{
   char input[1000];
   int received = socket_receive(input,1000);
   if (received > 0) 
   {
      input[received] = 0; // add the end mark
      printf("%s", input);
   }
   wait(1);
}



When i tried with TCP 1 i received "Can't connect to login server"
When i tried with UDP 0 i receivec "Connect to login server" and "message send ok" ... but the Receiver dont show anything...

I was read older posts and others answer but i cant find what and where i am doing wrong

Please tell me what i am doing wrong...

thx you all... and sorry for my english.

Best Regards
Dimitris

Re: socket_connect.... socket_send,,, [Re: NeoJT] #423443
05/29/13 20:29
05/29/13 20:29
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Hi, I used the socket functions a while ago for communication on the localhost via TCP. In the end we had best results with trying to connect first with hostname = NULL (which means connection on localhost) and then, if that failed (for whatever reason) on "localhost". I can't remember exactly why we decided so but somehow the code ended up like this. Since I never sent something back, I can only tell you about receiving.

For receiving, I used a global char string like this:

Code:
#define SOCKET_LEN 32
char g_chSocket [SOCKET_LEN];



because I received some text with encoded data, therefore I needed some more characters; and I needed to clear it before with strcpy and "". For the second parameter for socket_receive I choose SOCKET_LEN - 1, so 31 instead of 32 characters. I can't remember why, but I guess it is some string delimiter related thing. It is exactly the number of characters, because each character consumes a byte. To transform the received string, I copied it into a STRING* then, like this:

Code:
STRING* g_strSocket = "#32";

str_cpy(g_strSocket, g_chSocket);
str_trunc(g_strSocket, str_len(g_strSocket) - bytes);



for which bytes is the returned int value of socket_receive.


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