Author Topic: [Question] Regards TNET - Sending / Recieving Data!  (Read 3830 times)

jangan

  • Guest
[Question] Regards TNET - Sending / Recieving Data!
« on: February 19, 2013, 12:51:39 PM »
Hi everyone, I just bought a copy of TNET and i am still new to this entire thing of networking... I have been coding for many years in Java so its hard adjusting 100% to .net standards.

I am building:
- Server [Almost complete] - So far connects directly to a local database!
- Client [Not yet started]


What i am trying to do:
1) Player enters username/password on client
2) Client sends the username/password to the server
3) Server checks if they are correct
4) Sends back true or false



What i am asking to help me with is:
- How do i do the last part? how do i send data using TNET, "please assume i am using standalone or unity" I know a fair amount of C# but not that good with unity!



I also didn't buy TNET to make money or anything, i was just interested in learning communication coding and was hoping this is a good place to start! I want to eventually be able to send data back and forth! Eventually encrypt data or make it one way! Etc :D


Please feel free to write example tiny codes explaining this part! I am seriously stuck :O

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [Question] Regards TNET - Sending / Recieving Data!
« Reply #1 on: February 19, 2013, 08:11:42 PM »
For any kind of authentication you will want to create your own custom packets that will be handled on the server. Add a new packet type to the TNet.Packet enum (or better yet -- a pair: request and response), and add handling for these packets to the appropriate place on the server and client. To send a custom packet, use BeginSend / EndSend.

I might add a built-in authentication logic if I can make it generic enough.

blueskined

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: [Question] Regards TNET - Sending / Recieving Data!
« Reply #2 on: February 19, 2013, 10:09:53 PM »
I might add a built-in authentication logic if I can make it generic enough.

Please!Please!Please!Please!Please!Please!Please!Please!Please!Please!Please!Please!Please!Please!Please!Please!Please!Please!Please!Please!Please!

jangan

  • Guest
Re: [Question] Regards TNET - Sending / Recieving Data!
« Reply #3 on: February 19, 2013, 11:43:30 PM »
For any kind of authentication you will want to create your own custom packets that will be handled on the server. Add a new packet type to the TNet.Packet enum (or better yet -- a pair: request and response), and add handling for these packets to the appropriate place on the server and client. To send a custom packet, use BeginSend / EndSend.

I might add a built-in authentication logic if I can make it generic enough.

I spent few hrs on this and still cant figure it out :S I have been looking at examples like : http://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener.aspx - and - http://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient.aspx

Which is exactly what i wanted but i am trying hard to figure out how to integrate: TcpListener server = new TcpListener(localAddr, port); into TNET

OR


you can possibly tell me how do i send a single byte back and forth in TNET :S

I already understood the
  1. TNManager.client.BeginSend(...);
  2. TNManager.client.EndSend();

but i cannot figure out a way to receive it... i hope you can help me out with this!





///////// EDIT - 1///////////

Oh so i found out that TNGameServer uses TCPListener :O .. well at the moment i added this to GameServer ->
  1.  public TcpListener getListener()
  2.     {
  3.         return mListener;
  4.     }
  5.  

and created an instance in my code that uses the mListener inside of gameserver.


Do you see any problems with this Aren ?



////edit 2////

yeah nothing work... im getting frustrated trying to send at least a single byte accross tnet :S
« Last Edit: February 20, 2013, 01:37:57 AM by jangan »

broknecho

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 33
    • View Profile
Re: [Question] Regards TNET - Sending / Recieving Data!
« Reply #4 on: February 26, 2013, 05:34:49 PM »
Hi jangen,

Take a look at Aren's tutorial on custom packets:

http://www.youtube.com/watch?v=cmc_oIWmroI

That should give you the information you need to create a Authentication request and response.