Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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  
  UDP  (Read 4451 times)
0 Members and 1 Guest are viewing this topic.
Offline Nvec

Junior Newbie





UDP
« Posted 2009-11-03 20:31:37 »

Hello, im new in Java.
I testing UDP Client + Server , but i don't know how fix errors.
Maybe any can help me ?
Im testing this tutorial : http://www.corvstudios.com/tutorials/udpMultiplayer.php
Im run UDPServer.java and show on console:
1  
2  
User-PC
169.254.181.57

I run UDPClient.java and show on console:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
java.net.SocketException: Unrecognized Windows Sockets error: 0: Cannot bind
        at java.net.PlainDatagramSocketImpl.bind0(Native Method)
        at java.net.PlainDatagramSocketImpl.bind(PlainDatagramSocketImpl.java:82)
        at java.net.DatagramSocket.bind(DatagramSocket.java:368)
        at java.net.DatagramSocket.<init>(DatagramSocket.java:210)
        at java.net.DatagramSocket.<init>(DatagramSocket.java:261)
        at java.net.DatagramSocket.<init>(DatagramSocket.java:234)
        at UDPServer.ServerThread.<init>(UDPServer.java:100)
        at UDPServer.Game.<init>(UDPServer.java:46)
        at UDPServer.UDPServer.main(UDPServer.java:22)
Exception in thread "Server Thread" java.lang.NullPointerException
        at UDPServer.ServerThread.receivePacket(UDPServer.java:131)
        at UDPServer.ServerThread.run(UDPServer.java:115)

Maybe any can help me ?  Smiley
Thanks.  Wink
Offline DzzD
« Reply #1 - Posted 2009-11-03 23:27:22 »

Hello, im new in Java.
I testing UDP Client + Server , but i don't know how fix errors.
Maybe any can help me ?
Im testing this tutorial : http://www.corvstudios.com/tutorials/udpMultiplayer.php
Im run UDPServer.java and show on console:
1  
2  
User-PC
169.254.181.57

I run UDPClient.java and show on console:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
java.net.SocketException: Unrecognized Windows Sockets error: 0: Cannot bind
        at java.net.PlainDatagramSocketImpl.bind0(Native Method)
        at java.net.PlainDatagramSocketImpl.bind(PlainDatagramSocketImpl.java:82)
        at java.net.DatagramSocket.bind(DatagramSocket.java:368)
        at java.net.DatagramSocket.<init>(DatagramSocket.java:210)
        at java.net.DatagramSocket.<init>(DatagramSocket.java:261)
        at java.net.DatagramSocket.<init>(DatagramSocket.java:234)
        at UDPServer.ServerThread.<init>(UDPServer.java:100)
        at UDPServer.Game.<init>(UDPServer.java:46)
        at UDPServer.UDPServer.main(UDPServer.java:22)
Exception in thread "Server Thread" java.lang.NullPointerException
        at UDPServer.ServerThread.receivePacket(UDPServer.java:131)
        at UDPServer.ServerThread.run(UDPServer.java:115)

Maybe any can help me ?  Smiley
Thanks.  Wink

no sure but maybe check your firewall ?

Offline Nvec

Junior Newbie





« Reply #2 - Posted 2009-11-04 00:25:00 »

Check , but error has not changed.
And thanks for you reply DzzD!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #3 - Posted 2009-11-04 00:34:57 »

http://www.coderanch.com/forums/posts/watch/0/207423

Seems to mean you might have something else running on the same port? (though that doesn't really make sense with UDP does it?)

Kev

Offline DzzD
« Reply #4 - Posted 2009-11-04 01:05:34 »

Quote
Seems to mean you might have something else running on the same port? (though that doesn't really make sense with UDP does it?)
for a server it can

but wait, I just looked the link you posted, do you run it from an Applet ?! if so maybe a security issue also becarefull on your IP vs localhost, if the server is bind to your ip you wont reach it with localhost and vice-versa

Offline h3ckboy
« Reply #5 - Posted 2009-11-04 07:40:05 »

have you tried it within your LAN before.

like without port forwarding?
Offline Nvec

Junior Newbie





« Reply #6 - Posted 2009-11-04 14:48:34 »

Thanks all for replys.
Yes im use Windows 7 OS.
Im trying change ports ( im trying download Port Scanner etc.  Roll Eyes ) but error has not changed.
Maybe any test this tutorial on Windows ? what you port use ?
Offline h3ckboy
« Reply #7 - Posted 2009-11-04 18:47:59 »

I have donet hat tutorial on windows XP.

I used the default port.

I noticed that you are not using a local ip. you should try to do it with "localhost" and run both the client and the server on the same computer.
Offline Corvinex

Senior Member


Projects: 1


Work Hard, Go Pro.


« Reply #8 - Posted 2009-11-04 21:48:14 »

Hello, im new in Java.
I testing UDP Client + Server , but i don't know how fix errors.
Maybe any can help me ?
Im testing this tutorial : http://www.corvstudios.com/tutorials/udpMultiplayer.php
Im run UDPServer.java and show on console:
1  
2  
User-PC
169.254.181.57

I run UDPClient.java and show on console:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
java.net.SocketException: Unrecognized Windows Sockets error: 0: Cannot bind
        at java.net.PlainDatagramSocketImpl.bind0(Native Method)
        at java.net.PlainDatagramSocketImpl.bind(PlainDatagramSocketImpl.java:82)
        at java.net.DatagramSocket.bind(DatagramSocket.java:368)
        at java.net.DatagramSocket.<init>(DatagramSocket.java:210)
        at java.net.DatagramSocket.<init>(DatagramSocket.java:261)
        at java.net.DatagramSocket.<init>(DatagramSocket.java:234)
        at UDPServer.ServerThread.<init>(UDPServer.java:100)
        at UDPServer.Game.<init>(UDPServer.java:46)
        at UDPServer.UDPServer.main(UDPServer.java:22)
Exception in thread "Server Thread" java.lang.NullPointerException
        at UDPServer.ServerThread.receivePacket(UDPServer.java:131)
        at UDPServer.ServerThread.run(UDPServer.java:115)

Maybe any can help me ?  Smiley
Thanks.  Wink

It looks like your trying to run the server twice? If the client attempts to run, and you get UDPServer.java output then it seems like your IDE setup for running two separate java projects is running the same one.

"Do what you love and you'll never work a day in your life."
Android: Pac-Ball
Web Applet: Virus Effect
Old Games
Offline Nvec

Junior Newbie





« Reply #9 - Posted 2009-11-04 22:11:33 »

Thanks Corvinex and other for replys Smiley but error im can't/don't fixed  Undecided.
Corvinex maybe yau have compile this tutorial ? maybe can share ?  Smiley
I think in order then to understand me, why im can't running. Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Karmington

Senior Member


Medals: 1
Projects: 1


Co-op Freak


« Reply #10 - Posted 2009-11-06 16:49:30 »

Kay, let's walk through this, I just built the thing on eclipse and it worked fine.
Ouput:
owner-c6f2b00d5
192.168.100.22
null Connected
, then i get the circle moved on the screen with wasd.

How I built the project:
1) New Project
2) New Package, udpserver and udpclient
3) New Class, UDPServer in udpserver package and UDPClient in udpclient package
4) Copy code into the empty classes.
5) run server, run client.

Works for me. Socket bind exception is indeed most common if you have already bound the socket. Check you have no other instances running.
java.net.BindException: Address already in use: Cannot bind
   at java.net.PlainDatagramSocketImpl.bind0(Native Method)
comes for me if I try to launch another server.Make sure you terminate all the runners properly.
Use the red square to terminate. 8 steps right from the red stop button is a console selector,
'Display Selected Console', which should show you all running instances.

This will be particularly important to handle properly when you put this stuff on to the actual server,  if you forget a running program
it will keep blocking that port from new instances of the program.

Offline delt0r

JGO Coder


Medals: 22


Computers can do that?


« Reply #11 - Posted 2009-11-06 17:04:19 »

A problem we had once was that windows didn't properly clean up a previous bind. A restart did fix it, but we went for the add one to the port number each time or pick a random port number. This was on XP however.  Also you need special permission to bind to ports below 1024.

I have no special talents. I am only passionately curious.--Albert Einstein
Offline Sueamanu

Senior Newbie





« Reply #12 - Posted 2009-11-06 20:56:56 »

Yes work, but get on Applet error maybe any can help ?
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
java.lang.NoClassDefFoundError: UDPClient (wrong name: UDPClient/UDPClient)
   at java.lang.ClassLoader.defineClass1(Native Method)
   at java.lang.ClassLoader.defineClass(Unknown Source)
   at java.security.SecureClassLoader.defineClass(Unknown Source)
   at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
   at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
   at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NoClassDefFoundError: UDPClient (wrong name: UDPClient/UDPClient)
Offline DzzD
« Reply #13 - Posted 2009-11-06 22:13:39 »

Yes work, but get on Applet error maybe any can help ?
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
java.lang.NoClassDefFoundError: UDPClient (wrong name: UDPClient/UDPClient)
   at java.lang.ClassLoader.defineClass1(Native Method)
   at java.lang.ClassLoader.defineClass(Unknown Source)
   at java.security.SecureClassLoader.defineClass(Unknown Source)
   at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
   at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
   at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NoClassDefFoundError: UDPClient (wrong name: UDPClient/UDPClient)

wrong package name (can you opst your applet code?)

Offline Sueamanu

Senior Newbie





« Reply #14 - Posted 2009-11-12 17:33:37 »

Thanks.  Smiley
Offline Sueamanu

Senior Newbie





« Reply #15 - Posted 2009-11-20 14:19:38 »

Applet HTML code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
<html>
<head>
</head>
<body>
   <applet code="UDPClient.class" width="640" height="480">
        <param name="username" value="Guest">
        <param name="ip" value="localhost">
        </applet>
</body>
</html>


Error:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
java.lang.NoClassDefFoundError: UDPClient (wrong name: UDPClient/UDPClient)
   at java.lang.ClassLoader.defineClass1(Native Method)
   at java.lang.ClassLoader.defineClass(Unknown Source)
   at java.security.SecureClassLoader.defineClass(Unknown Source)
   at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
   at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
   at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NoClassDefFoundError: UDPClient (wrong name: UDPClient/UDPClient)
Offline indexunknown

Junior Member





« Reply #16 - Posted 2009-11-20 14:54:12 »

If u have exported it into a .jar then u need to put it into the tag <applet code="UDPClient.class" archive="jar name goes here" width="640" height="480">
also make sure all the files are in same directory with the page.html .
Offline Sueamanu

Senior Newbie





« Reply #17 - Posted 2009-11-20 17:31:59 »

I'm test and too get error ( error don't change ).
Offline Corvinex

Senior Member


Projects: 1


Work Hard, Go Pro.


« Reply #18 - Posted 2009-11-20 20:42:52 »

Yea, make sure the UDPClient.class file is going into the same directory as your applet .html file.

I reproduced your error by not having the .class files in the same folder as the .html file:
1  
2  
3  
4  
5  
6  
7  
8  
java.lang.ClassNotFoundException: UDPClient.class
   at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
   at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
   at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)


this is what your folder should contain
UDPClient
  • Player.class
  • PlayerList.class
  • ReceiveThread.class
  • UDPClient.class
  • UDPClient.html

and then double click UDPClient.html, and the client should run.

"Do what you love and you'll never work a day in your life."
Android: Pac-Ball
Web Applet: Virus Effect
Old Games
Offline Sueamanu

Senior Newbie





« Reply #19 - Posted 2009-11-20 21:44:35 »

.
Offline indexunknown

Junior Member





« Reply #20 - Posted 2009-11-20 21:56:08 »

if the class is in package UDPClient then u need
<applet code="UDPClient/UDPClient.class" archive="UDPClient.jar" width="640" height="480">

probably without archive then:
<applet code="UDPClient/UDPClient.class" width="640" height="480">
Offline Sueamanu

Senior Newbie





« Reply #21 - Posted 2009-11-20 22:15:17 »

Yes! work! , but i'm on client can't move ball and other.

Thanks all for help and reply's! Smiley
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.

xsi3rr4x (56 views)
2014-04-15 18:08:23

BurntPizza (54 views)
2014-04-15 03:46:01

UprightPath (67 views)
2014-04-14 17:39:50

UprightPath (50 views)
2014-04-14 17:35:47

Porlus (67 views)
2014-04-14 15:48:38

tom_mai78101 (91 views)
2014-04-10 04:04:31

BurntPizza (152 views)
2014-04-08 23:06:04

tom_mai78101 (248 views)
2014-04-05 13:34:39

trollwarrior1 (205 views)
2014-04-04 12:06:45

CJLetsGame (212 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!