Skin designed by Auron89.Find more great skins at Silent Designs!
Image hosted by Photobucket.com


Pages: (4) [1] 2 3 ... Last » ( Go to first unread post )

 Fixed section 3 part 2 tutorial 2
machra
Posted: Jul 21 2005, 05:24 AM


Regular


Group: Members
Posts: 27
Member No.: 98
Joined: 20-February 05



its not worth uploading new code but basically if u run the serverand stop it and start it again u get an error saying its already running. if u run the server and close it i think it gives another type of error. so in the code go to the declarations
in clsserver an paste this over whats there
CODE
Public Class clsServer
   Public Clients As New Collection
   Private Listener As TcpListener
   Private t As System.Threading.Thread
   Private reader As System.IO.StreamReader
   Public runserv As Boolean

then in start listening paste it with this
CODE
Public Sub StartListening()
       'We'll use the local IP (127.0.0.1) and port 3998
       Listener = New TcpListener(IPAddress.Parse("127.0.0.1"), 6580)
       Listener.Start()
       t = New System.Threading.Thread(AddressOf ListenContinuously)
       t.Start()
       runserv = True
   End Sub

and finnaly in stop listening add this
CODE
 Public Sub StopListening()
       If runserv = True Then
           t.Abort()
           Listener.Stop()
       Else
       End If
   End Sub


its real easy 2 see what i added but pretty much it adds a boolean called runserv whcih when the server is running it declares then and when the stop server is clicked it closes all parts of the server allowing it 2 be started up again without closing the app. Pretty much now u can start and close server without getting an error or being forced to close the app before starting it up again. also thanks for tutorial it helped me out as far as learning the basics. gotta finish that sending a text message soon im dieing to see it. you've made the shortest tutorials that made sense to me so far.
Top
The Pentium Guy
Posted: Jul 21 2005, 05:46 AM


The Boss.


Group: Admin
Posts: 743
Member No.: 1
Joined: 4-July 03



I haven't done work with networking since that tutorial wink.gif. Sorry for keeping you waiting, here are the tutorials I'm going to do next, in order:

RPG Programming Series: Optimizations
Direct3D: Introduction to 3D Transformations

So once I finish those I'll think about networking. I'm pretty much a beginner when it comes to networking, unfortunately. I really wish I could help, but I need some places to learn from smile.gif. My next tutorial in the networking series is making the thing send a message across the internet as opposed to making it local. Given an IP address (I'll discuss port forwarding and such), and given that that person is running your program, you can send a message to them.

That said, I did finish a basic chat program (UBER basic) - it's "global chat" basically. I'll upload the code here if you want, I haven't yet figured out how to explain all of it so I'll upload the code here before making a tutorial on it for those of you who are waiting tongue.gif.

Thanks for the code, I overlooked my mistake. I'll update the tutorial soon after I get back from vacation (next week).

-The Pentium Guy
Top
machra
Posted: Jul 21 2005, 04:34 PM


Regular


Group: Members
Posts: 27
Member No.: 98
Joined: 20-February 05



heh. me 2. well im going over that tutorial on networking line for line triyng to figure out how it works. while i look over another set of code from a chat program. puting 2 and 2 together. as soon as i figure that out ill try and help with those networking tutorials if i can. umm yeah can i see the basic chat program smile.gif it might help me find what im looking for heh. at microsofts download center there is a 101 vb samples all for vb.net 1 program in there is a sockets program its a basic chat between server and client. id send link but im not sure where it was. if u find it then it might be helpful later on when u do those tutorials
Top
tezzanator
Posted: Jul 21 2005, 07:07 PM


Regular


Group: Members
Posts: 26
Member No.: 127
Joined: 2-July 05



on the subject of networking how would i trigger a sub over the web? been wanting to trigger stuff like a label and stuff lol

oh ye the link smile.gif

http://msdn.microsoft.com/vbasic/downloads...es/default.aspx
Top
machra
Posted: Jul 22 2005, 10:23 AM


Regular


Group: Members
Posts: 27
Member No.: 98
Joined: 20-February 05



tazz.. i woudlnt really know how 2 trigger a sub over tcp ip directly but you could give the "client" a set of text commands that do things like that example dim runsub1 as string
if runsub1 = "12345" then
mysub()
end if

then on server side a button called runsub1 when clicked sends a message that after doing all the code inputs "12345" into the string causing the rest to execute. im not sure if this works 100 percent as im still trying to get a tcp client server chat working. but it looks like it would work for the most part. btw pentium guy i figured out how 2 send a message via client types message presses send button then server recieves it then displays in text box and sends popup just like the login example u included in the tutorial (excluding text box) only problem is that on the server side i needed a button and it only recieves text if it was pressed. and if u pressit but dont recieve a message soon it hands. i figured a infinite loop could replace the button command that checks for a sent message from the client
but i sorta get lost in how 2 get the loop running. i noticed u were working on that with the pole sub i think i know what ur going with that
CODE
listener.AcceptSocket.Poll(1, SelectMode.SelectRead)

something on the lines of that ? tell me if im wrong. anyways i looked at that and another clientserver proggy that has that loop i want
CODE
whole code
           If _HostSocket.Poll(1, SelectMode.SelectRead) Then
               ' _HostSocket has data to be read.
               ' Call the Socket Available method on _HostSocket;
               ' assign the return value (Bytes available) to an integer variable.
               Dim numBytes As Int32 = _HostSocket.Available
               ' Instantiate an array of Bytes which is the size of the
               ' number of Bytes available.
               Dim Data(numBytes) As Byte
               ' Call the Socket Receive method.
               ' Receives data from a connected Socket.
               _HostSocket.Receive(Data)
               ' Convert the Byte array received into a String
               HostMessagesReceivedTextBox.Text &= System.Text.ASCIIEncoding.ASCII.GetString(Data)
               HostMessagesReceivedTextBox.Text &= ControlChars.CrLf
               ' Stop _Timer. Message was received and processed.
               _Timer.Stop()
           End If
thats with the comments in it. diffrence is that it converts the message into bytes then changes it back. which well ur tutorial so far doesnt and neither does what im doing.
CODE
what im doing.                 reader = New System.IO.StreamReader(pendingClient.GetStream)
               message = reader.ReadLine()
               MessageBox.Show(message)
               TextBox1.Text = message
im thinking im missing something really simple as far as the loop goes with waiting for a message 2 be sent from the client. i tried
CODE
if listener.Pending = True  checkmessagesub()
which then executed the lines above but when i pressed the send button onthe client side it didnt executre the streamreader code which has me puzzled so far. if u have any clue what im saying above and know how ican fix this please tell me. BTW : as soon as i get this working within the next few days or weeks imma fully comment it to my best commenting skills (which r poor havent commented a program in my life, bad habbits) anyways ill do that and send it to you so that you have 1 tutorial you dont have to do smile.gif heh. and after that since its in relations to what im working on ill make another tcp ip tutorial that connects a client to a server then checks for login id and password in a text filein the directory of server. since well most ppl are looking for ways to make multiplayer games mainly rpg's in visual basic and what not.


(fixed added another multithread so that i had something to execute the loop. oddly enough thatwas how i shoulda done it inthe beginning but i never thought of it)

EDIT: anyone reading this i got alot of typhos like in there it says hands i meant hangs sry for that hehe.. it was 3 am i wasnt really paying attention or caring for that matter what my spelling looked like. and as u can tell i dont use periods to often and sometimes i use them when i dont need to eh... like now (punctuation = horrible) n e ways try and ignore that 2 and put periods where u think they belong tongue.gif
Top
The Pentium Guy
Posted: Jul 23 2005, 03:49 AM


The Boss.


Group: Admin
Posts: 743
Member No.: 1
Joined: 4-July 03



*blinks*

QUOTE

while i look over another set of code from a chat program. puting 2 and 2 together.


Exactly what I've been doing with everything basically: DirectX, Networking, GDI+. Just by looking at different code you can figure out how this stuff works, and learn new tricks. That's what I did with this Networking tutorial too.

Once I get back (3-4 days) I'll upload a few code snippets I found while snooping around the web. It might help you guys out a bit.

Or, wait a sec. Me and elNerdo (a member vbProgramming forums) were testing my "send-a-message-over-the-internet" program a while ago. Since I don't have it here, I'll PM him and ask him if he could possibly upload it (to my new server haha biggrin.gif).


QUOTE

btw pentium guy i figured out how 2 send a message via client types message presses send button then server recieves it then displays in text box and sends popup just like the login example u included in the tutorial (excluding text box) only problem is that on the server side i needed a button and it only recieves text if it was pressed. and if u pressit but dont recieve a message soon it hands.i figured a infinite loop could replace the button command that checks for a sent message from the client


Long, confusing sentence wink.gif. It's a bit early in the morning (I just got up) so haha, that just went way over my head. I think I should read it again a little more slowly XD.

Ok now I understand. (I highlighted what I'm talking about in Bold). You're on the right track, with the Poll sub.

If I remember correctly (I haven't programmed in 6 weeks, been on vacation), just create another thread for the Poll sub (see Multithreading tutorial) and run the Poll sub in an infinate loop and keep checking for messages.

'Pseudocode
CODE

Public Sub PollForMessages()
   Dim s as String
   While ServerIsRunning 'This will be set to True until you stop the server
         s = myStreamReader.readLine()
         If not s = "" then
             'You've got a new message
             MessageBox.Show(s)
         End If
   End While
End Sub



But make sure you run the Poll thread in a sub (AFTER the server finishes initializing).

So if I remember correctly, Private pollThread as Thread in your globals

CODE

Public Sub InitializeServer()
  '<-----------Lots of code snipped out---------->
  pollThread = new Thread(AddressOf PollForMessages)
  pollThread.Start()
End Sub


And remember to stop the thread once the server stops.

EDIT! Ignore all of this. In my tutorial I already have a thread, t, running.
CODE

Private Sub ListenContinuously()
   While True = True

       If Listener.Pending = True Then
           AcceptClient()
       End If

       'PollForMessages() <This is for a later tutorial. That's why this line is commented out>
   End While
End Sub

Just uncomment the PollForMessages line and you should be all set.

QUOTE

im thinking im missing something really simple as far as the loop goes with waiting for a message 2 be sent from the client. i tried
CODE
if listener.Pending = True  checkmessagesub()

Nope. The Listener.Pending flag only tells you if a new CLIENT is coming to join.

QUOTE

diffrence is that it converts the message into bytes then changes it back.

You probably have more experience than me in networking. I'm willing to listen: Why change it to Bytes? Would it be more compressed?

I'm gonna experiment with one thing. We've done (so far) TCPListener and TCPClient. I beleive there's something called TCPServer, it could have some functions to dynamically process messages. Not sure, I'll experiment around when I get back.

-The Pentium Guy
Top
machra
Posted: Jul 23 2005, 04:04 AM


Regular


Group: Members
Posts: 27
Member No.: 98
Joined: 20-February 05



thanks very much that was basically what i was trying 2 do in a nut shell. sept my code unlike that is very messey , un commented, hard 2 understand by anyone else, and sometimes myself cause im trying multiple solutions 2 one problem then when one solution doesnt work i gotta goback and figure out what my idea was for the other way. hehe, well when you get back work on ur other tutorials cause ill most likely hve this thing down now that u pasted that code. btw the lengthy sentace... ehh ignore it sometimes i ramble on talking about something confusing thinking everyone who is reading it knows what im saying heh. i may or may not have this done actually in a few days.. taking a whole semester in college wrapped up into 5 weeks so i got alot of things to study for in the upcoming exam.. :*( but for the sake of the mmorpg in vb game programmers out there ill do it for all of you hehe and myself tongue.gif and ehh if anyone is keeping up on the posts in this topic, just a word of advice. do like pentium guy says look at other ppls code (Not one person but many persons as there are many solutions to one problem, which ive clearly seen trying 2 make this tcp/ip program) , look at others code and then instead of copy pasting it all your self rewrite it and figure out why each thing was done. by rewriting it you can go line for line learning the other persons code and see why its there. and if ur still stumped on something come here cause the pentium guy in my opinion has the best tutorials out there so far cause he explains it in the tutorial really really well. tongue.gif
Top
The Pentium Guy
  Posted: Jul 23 2005, 04:22 AM


The Boss.


Group: Admin
Posts: 743
Member No.: 1
Joined: 4-July 03



Cool wink.gif.
I used to have the same problem myself.... until I realized the importance of good commenting, and long variable names***.

Earlier I wanted to get a project done ASAP (becuase VB is RAD, Rapid Application Development, right). But now I realize that, especially for bigger projects, you're doomed from the start if you do this. I've had to rewrite entire projects just because of messy code.

Glad you enjoy the tutorials.
-The Pentium Guy

***No. Not LONG varible names like ThisVariableTellsYouHowManyLivesTheBlackPenguinHas_IfThisValueIsZeroThenCall_TheGameOverSub, but more like descriptive names.
Top
machra
Posted: Jul 23 2005, 04:43 AM


Regular


Group: Members
Posts: 27
Member No.: 98
Joined: 20-February 05



heh yeah after i get this program done im commenting every line... i look at the simple rpg game that well isnt done cause there r no enemies or anything other then a character who can save and load place on a half mapped map hehe. never really got any further then jsut a prototype with it cause it was all i needed for future refrence.. and well im refrencing it now and ehhhh i dont know why i did what i did sometimes hehe.
Top
machra
Posted: Jul 23 2005, 05:12 AM


Regular


Group: Members
Posts: 27
Member No.: 98
Joined: 20-February 05



just reread over ur message on poll etc... yeah until a week ago i never did any network programming what so ever heh. but i read some vb6 networking codes winsock etc... WOW is that stuff simple, there is even a .dll someone made that recreates the winsock in vb6 for use in vb.net i considered using it but then i thought... why go the easy way imma regret it later when i need 2 find out how too do something relating to client server stuff and i wont know what to do. so im learning it the hard way smile.gif ive read a big on why they convert to bytes and send pretty much its cause its easier to convert to bytes and send a message then doing it they way u and i are which is using streamreader and streamwriter. when using bytes pretty much instead of using streamreader and streamwriter its
CODE
' if this were a client server program on one form / project so 2 speak this is  code in a nutshell and doesnt really work...
private clientsocket as socket
private serversocket as socket
'declare other things that connect client and server
clientsocket.Send(Buffer, 0, Buffer.Length, SocketFlags.None)
dim numBytes As Int32 = _HostSocket.Available
Dim Data(numBytes) As Byte
serversocket.Receive(Data)

and that and more code is suppose 2 connect client 2 server , send a text message that is converted 2 bytes before sent. then when server loop runs (which isnt in that code above) it recieves any bytes that are sent and then code that isnt included converts the bytes into textbox1.text which is the message sent.. im not 2 good at showing examples heh but i think i got that code from the socket demo in 101 vb.net programs. the prgoram is called demosockets so google might help ya find it and explain better then i did.

summed up bytes are just used because its a diffrent way to send a message then streamread streamwrite
Top
tezzanator
Posted: Jul 23 2005, 11:50 AM


Regular


Group: Members
Posts: 26
Member No.: 127
Joined: 2-July 05



that kinda worked smile.gif but i found a ready made program for my lego (wich was what i wanted it for) you can have a look at it at www.pc-help.jt7.net then click webcam tongue.gif its fully controlable , the server is written in vb i think smile.gif webpage is java
Top
The Pentium Guy
Posted: Jul 23 2005, 04:55 PM


The Boss.


Group: Admin
Posts: 743
Member No.: 1
Joined: 4-July 03



QUOTE


' if this were a client server program on one form / project so 2 speak this is  code in a nutshell and doesnt really work...
private clientsocket as socket
private serversocket as socket
'declare other things that connect client and server
clientsocket.Send(Buffer, 0, Buffer.Length, SocketFlags.None)
dim numBytes As Int32 = _HostSocket.Available
Dim Data(numBytes) As Byte
serversocket.Receive(Data)

.... Nice..... Possibly this offers a performance increase because you send data across the stream by use of a socket as opposed to writing to the stream itself.

Thanks for the info!
Top
The Pentium Guy
Posted: Jul 23 2005, 04:58 PM


The Boss.


Group: Admin
Posts: 743
Member No.: 1
Joined: 4-July 03



QUOTE (tezzanator @ Jul 23 2005, 07:50 AM)
that kinda worked smile.gif but i found a ready made program for my lego (wich was what i wanted it for) you can have a look at it at www.pc-help.jt7.net then click webcam tongue.gif its fully controlable , the server is written in vb i think smile.gif webpage is java

HOLY...FREAKING..CRAP!!
you made a CONTROLLABLE webcam? So when I hit "right" the webcam actually MOVES right?

Edit: D'oh I see a black screen. Been waiting for a full minute now (IE 6.0/Latest Windows Media Player). Must be the firewall. I'll check it out when I get on my home computer.
Top
tezzanator
Posted: Jul 23 2005, 05:55 PM


Regular


Group: Members
Posts: 26
Member No.: 127
Joined: 2-July 05



nope it was black coz i was playing unreal tournament lol when i play it i shut off the video server smile.gif or i lag like hell tongue.gif

and yes it does mover right when u click it wink.gif but there is a 10 sec delay on the video tongue.gif i seriously need better video streaming software , any suggestions??

i saw someone move it about 2 hours ago or 4 dunno tongue.gif was that you? tongue.gif i think u moved down or summat ^^ i was playin unreal when u did it like tongue.gif

oh btw its online now if u wanna have a go biggrin.gif
Top
machra
Posted: Jul 23 2005, 11:27 PM


Regular


Group: Members
Posts: 27
Member No.: 98
Joined: 20-February 05



ha thats awesom. i went to check it out but it was black... server must have been off again. im trying hard 2 make a working client server chat program with multiple clients at once... i have problem with the threads and what not and well its a little hard 2 explain unless i show code.. so ill wait for you to get back and ill attach where im at (i should get further today)
Top


Topic OptionsPages: (4) [1] 2 3 ... Last » Quick Reply




Hosted for free by InvisionFree (Terms of Use: Updated 7/7/05) | Powered by Invision Power Board v1.3 Final © 2003 IPS, Inc.
Page creation time: 0.1289 seconds | Archive

Check out the Shoutbox! Type in your name and the message to shout ;).