Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [Kryonet] Receiving Tcp message issue  (Read 257 times)
0 Members and 1 Guest are viewing this topic.
Offline saucymeatman
« Posted 2014-01-02 21:00:26 »

I am trying to set up a basic server client pair and am able to connect the client to the server, but when the client uses transmission control protocol to send an object it is never recieved.

Here is the server :

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;
import com.esotericsoftware.kryonet.Server;
import com.esotericsoftware.minlog.Log;

public class ChatServer {
   PrintWriter log;
   public static void main(String[] args) {
        Server server = new Server() {
            protected Connection newConnection () {
               //System.out.println("   Server : Client Connected");
           PrintWriter writer;
            try {
               writer = new PrintWriter("ClientConnected.txt", "UTF-8");
                writer.close();
            } catch (FileNotFoundException e) {
               e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
               e.printStackTrace();
            }
            return new ChatConnection();
            }
        };
     
       Kryo k = server.getKryo();
       k.register(Request.class);
     
       server.addListener(new Listener() {
            public void received (Connection c, Object object) {
            PrintWriter writer;
            try {
               writer = new PrintWriter("RecievedAMessage.txt", "UTF-8");
                writer.close();
            } catch (FileNotFoundException e) {
               e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
               e.printStackTrace();
            }
            /*
             if (object instanceof Request) {
                Request request = (Request)object;
                System.err.println(request.text);
               
                Response response = new Response();
                response.text = "Thanks";
                connection.sendTCP(response);
             }
             */

           }
        });
       
       try {
         server.bind(6661, 6662);
      } catch (IOException e) {
         System.err.println("Error : Couldnt establish server on requested port(s)");
         System.exit(1);
      }
       server.start();
   }

   static class ChatConnection extends Connection {
        public String name;
   }
}



And the client :

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JFrame;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryonet.Client;
import com.esotericsoftware.kryonet.Listener;


public class ChatClient {
   static Client client;
   public static void main(String[] args) {
      client = new Client();
       client.start();
       
       Kryo k = client.getKryo();
       k.register(Request.class);
       
       System.out.println("Client has started");
       try {
         client.connect(5000, "Mufasa", 6661);
         System.out.println("Client has connected");
      } catch (IOException e) {
         System.err.println("Unable to conneI ct");
         System.exit(1);
      }
       
       JFrame frame = new JFrame();
       frame.setSize(400,300);
       frame.setVisible(true);
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       JButton sendButton = new JButton("Send");
       sendButton.setSize(100,50);
       sendButton.addActionListener(new ActionListener(){
         @Override
         public void actionPerformed(ActionEvent arg0) {
            System.out.println("Sending...");
             Request request = new Request();
             request.text = "Here is the request";
             client.sendTCP(request);
             System.out.println("Sent");
         }
       });
       frame.add(sendButton);
       System.out.println("GUI Loaded");
   }
}


The server should create a blank text file called Recieved.txt when it recieves anything. It does create a blank text file called Connected.txt when the client connects.

Also it is just a LAN server client pair, my computer name is Mufasa so that is the in place of the IP adress.

Thanks in advance.
Offline saucymeatman
« Reply #1 - Posted 2014-01-02 23:48:05 »

If no one is able to help, does anyone have a simple server client pair they can share?
Offline wreed12345

JGO Knight


Medals: 24
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« Reply #2 - Posted 2014-01-03 01:26:31 »

I would recommend to try working out the problem with a less complicated CLI program using only println statements so you only have to worry about the kryonet code rather than everything else on top of it

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline saucymeatman
« Reply #3 - Posted 2014-01-03 02:06:22 »

Thanks for the response.
I fixed everything.
The only Issue was that I was using .sendTCP(object) instead of .sendUDP(object)
Offline wreed12345

JGO Knight


Medals: 24
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« Reply #4 - Posted 2014-01-03 02:22:24 »

didn't you want to use tcp ?  Huh

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (37 views)
2014-07-24 01:59:36

Riven (38 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (50 views)
2014-07-17 23:47:54

danieldean (42 views)
2014-07-17 23:41:23

MustardPeter (44 views)
2014-07-16 23:30:00

Cero (60 views)
2014-07-16 00:42:17

Riven (57 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!