score:0
replace
socket clientsocket = new socket("ip of my laptop here", 6789);
with
socket clientsocket = new socket(server address, 6789);
score:0
on your command prompt,
type:ipconfig
this will give the ip address of your machine.
now assuming that you are running the server code on your machine, pass the ip address retrieved from step 1 to the client code (the code run by your friend who is the client):
socket clientsocket = new socket(<here goes the ip address of the server machine>, 6789);
now, whichever machine is running the client code will need to pass on the ip address of the server machine, so that it can connect with each other. so if you want to chat with your friend, after running the server class code, run the client class code too. now both of you are connected to the server and can chat.
score:1
to create client socket you need to use the server's ip address not yours.
package connect1;
import java.io.*;
import java.net.*;
import javax.swing.joptionpane;
import java.util.scanner;
class tcpclient {
public static void main(string argv[]) throws exception
{
string sentence;
string modifiedsentence;
bufferedreader infromuser =new bufferedreader(new inputstreamreader(system.in));
socket clientsocket = new socket(inetaddress.getbyname("server_ip"), 6789);
dataoutputstream outtoserver =new dataoutputstream(clientsocket.getoutputstream());
bufferedreader infromserver =new bufferedreader(new inputstreamreader(clientsocket.getinputstream()));
system.out.print("enter characters to be capitalized: ");
sentence =infromuser.readline();
outtoserver.writebytes(sentence + '\n');
modifiedsentence = infromserver.readline();
system.out.println("from server: " + modifiedsentence);
scanner input=new scanner(system.in);
//system.out.print("do you want to enter again? press '0' for 'yes' and '1' if 'no'.");
//i=input.nextint();
}
}
replace "server_ip" by server's ip.
Source: stackoverflow.com
Related Query
- Connecting two computers(machines over a wireless network)
- setSelectionProvider over two different controls not working
- Connecting two java project
- pydev coverage: pytest and local pytest plugin running in two separate processes, talking over http
- While Connecting files Network error issue in Eclipse
- connecting two java frame
- IntelliJ show JavaDocs tooltip on mouse over
- Class JavaLaunchHelper is implemented in both ... libinstrument.dylib. One of the two will be used. Which one is undefined
- How do I compare two files using Eclipse? Is there any option provided by Eclipse?
- Eclipse: have the same file open in two editors?
- Any reason to prefer getClass() over instanceof when generating .equals()?
- Easy way of running the same junit test over and over?
- How to share Eclipse configuration over different workspaces
- Class JavaLaunchHelper is implemented in both. One of the two will be used. Which one is undefined
- How can I compare two revisions in git in Eclipse?
- Xcode - How to view two files side-by-side?
- Eclipse Kepler not connecting to internet via proxy
- Run two Java programs from Eclipse at once?
- What are the advantages of IntelliJ over Eclipse?
- How to synchronize files over FTP with Eclipse RSE?
- how to - github two factor authentication with eclipse
- Connecting a MySQL database to Glassfish classpath is not set or classname is wrong
- How to copy plugins between two eclipses
- SVN error on connecting with eclipse
- EGit - SSH Fails at Passphrase (when connecting to GitHub)
- What is the best way to share common code (such as domain classes) between two or more projects?
- Eclipse Java remote debugger extremely slow over VPN
- PHP Eclipse Xdebug two or more requests at a time
- Unable to Finish connecting to SonarQube server
- Java is scaling much worse than C# over many cores?
More Query from same tag
- How to fix Error in Maven build for new spring boot application intialized from start.spring.io
- How to import and compile Android FBReaderJ source code into Eclipse (Windows)?
- Lambda and cast intersection type (Eclipse compiler bug)
- How can I get(know) the menuid of a specific menu in eclipse?
- Custom attributes are logging in new line while using Custom Logging in Jetty 10
- java.lang.VerifyError: Cannot inherit from final class
- Android: Runtime crash when added SDK_INT code
- Java variable not being affected
- FATAL EXCEPTION: AsyncTask #1 do in background error with JSON
- Unit Testing / Eclipse / Command Line
- How can I execute tests automatically
- Is it possible to map a hotkey to "compare to each other" in eclipse?
- import slidingmenu library in Eclipse Indigo Service Release 2
- Does the textmate vertical selection feature exist in Flex Builder or Eclipse?
- how to save the value of a jspinner from change listener
- Compilation Errors after Maven successfully downloaded Jars
- Eclipse Oxygen - projects disappear
- cannot start eclipse neon on macOS Sierra
- Maven SCM Handler for CVS in Eclipse (Juno)
- How to make the color theme inside #ifdef more readable in Eclipse?
- Error : The type com.sun.syndication.feed.synd.SyndFeedI cannot be resolved. It is indirectly referenced from required .class files
- resources visible in eclipse but not in jar
- Android Eclipse issue Failed to create BuildConfig class
- how to rectify my error by using sonar
- Blackberry Package Project for Multiple OS Targets/Versions
- Files inside WAR appear double
- Initialization of variable java
- Maven: exclude resource from war
- Jar Can't Find Main Method - Connected to main class, but can't access method
- Spring Boot application.properties value not populating and not reading